Rama Lingam
Rama Lingam

Reputation: 11

Can not send email with php mailer using gmail account

Here i cannot send the email with PHPMailer using my gmail account. Sample Code:

<?php
require_once('phpmailerclass/class.phpmailer.php');

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 568;
$mail->SMTPSecure = 'ssl';

$mail->Username = "myEmail@gmail.com";
$mail->Password = "myPassword";

$mail->IsHTML(true); // if you are going to send HTML formatted emails

$mail->From = "ramalingam.p@pickzy.com";
$mail->FromName = "Ramalingam";

$mail->addAddress("yoursramalingam@gmail.com","Luu Van Minh");

$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";

if(!$mail->Send())
{
     echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
}   
else
{
    echo "Message has been sent";
}      
?>

Response Error:

Message was not sent

PHPMailer Error: The following From address failed: myEmail@gmail.com

I am also enable 'less secure' in gmail settings. But it will throw above the error. Specifying my VALID gmail From address. Please correct where i am wrong.

Upvotes: 0

Views: 1935

Answers (1)

Kiritkumar
Kiritkumar

Reputation: 486

if you use ssl then change port 587 to 465

$mail->Port = 465;
$mail->SMTPSecure = 'ssl';

https://support.google.com/a/answer/176600?hl=en

Upvotes: 7

Related Questions