Deeban Babu
Deeban Babu

Reputation: 729

SMTP mail trigger is not working

I tried to send a mail using smtp server in php mailer function.

This was the error am getting when I triggered this.

Am using the gmail mail server.

SMTP connect() failed.

require_once(TEMPLATEPATH . '/PHPMailer-master/PHPMailerAutoload.php');
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "xxxx";
//Password to use for SMTP authentication
$mail->Password = "xxxx";
//Set who the message is to be sent from
$mail->setFrom('xxxx', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('xxxxx', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('xxxx', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
$mail->msgHTML('test');

$mail->AltBody = 'This is a plain-text message body';
//Attach an image file


//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

This is my code. Please suggest what is the mistake in my code or where to check smtp connection failed error.

Thanks in Advance.

Upvotes: 0

Views: 457

Answers (1)

Amrinder Singh
Amrinder Singh

Reputation: 5502

Well, that's why it didn't work ,
Open your php.ini and search for this line ;extension=php_openssl.dll and remove the semi colon before it , save the file and restart your webserver. You will see your coding working after you do this change.

and set your host as follow:

$mail->Host = "ssl://smtp.gmail.com"; 

Upvotes: 1

Related Questions