phpmailerwindows-server-2012-r2php-7.2wamp64

WinServer 2012 r2 + PHP(wamp64) PHPMailer error “Could not instantiate mail function”


I tried all the steps which are prompted in win server 2012 r2 relates answer including its related answers and particular PHPMailer too.

But still, I'm running with the same issue. Additionally, have checked about port 25 is running no firewall issue here.

If anyone can help me, it's really appreciated.

NOTE:
Win server 2012 r2 relates answer
PHPMailer answer

server fault answer Thanks

UPDATE

//To test is via basic mail function
/*
mail("from_to_email@example.com", "Test Subject", "Test Message");
*/

//To Test via PHPMailer 

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';

//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = "from_email@example.com";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("to_email@example.com"); //Tried $mail->addAddress("to_email@example.com", "test name"); and third param too. 

//Send HTML or Plain Text email
$mail->isHTML(true); //Tried with false too.

$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPDebug = 3;
$mail->SMTPSecure = 'ssl';

// optional
// used only when SMTP requires authentication  
$mail->SMTPAuth = true;
$mail->Username = SMTP_EMAIL_HERE;
$mail->Password = SMTP_PASS_HERE;

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

Even, I tried my SMTP credential via online SMTP Tool and it's working fine but above code isn't.

NOTE: I verified about PHP/Apache modules availability and it's there so no issue about the module.


Solution

  • Two mistakes.

    You’re not calling isSMTP(), so none of your SMTP config is having any effect, and it’s using the mail() function, as I said in my comment.

    In your SMTP config, you’re using SMTPSecure = ‘ssl’ on port 587. That combination will not work; either change to port 465 or switch to ’tls’ mode.

    All of the SMTP code examples provided with PHPMailer follow this pattern, and it’s documented extensively in the troubleshooting guide.

    All in all this is why you need to search before you post, read docs, and post your code in your question.