I have php source code which is used to send email. I have used phpmailer class and gmail id to send mail. It was working fine from last 1 year But currently it stop working and through below error:
"The following From address failed: your@gmail.com"
Below was my source code :
<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$body="email body \n";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "your-gmail-Id@gmail.com"; // GMAIL username
$mail->Password = "gmail password"; // GMAIL password
$mail->SetFrom('your-gmailid@gmail.com', 'Metropolis Delhi');
$mail->AddReplyTo('your-gmailid@gmail.com', 'Metropolis Delhi');
$mail->Subject ="Email Subject";
$mail->Body =$body;
if(!$mail->Send())
{
echo $mail->ErrorInfo;
return false;
}
else
{
echo "Email Sent to !". $collname;
}
?>
To solve this problem, First I login to gmail and go to ''setting' => Account and Import => update correct "Send mail as" i.e. correct "From name" and email.
But problem is still not solved.
Now I change ssl to tls and port no 587 in my code.
Now it is working fine. Below is code which is working fine.
<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$body="email body \n";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "your-gmail-Id@gmail.com"; // GMAIL username
$mail->Password = "your-password"; // GMAIL password
$mail->FromName="From Name"; // correct from name
$mail->From="your-gmailId@gmail.com";
$mail->AddReplyTo('your-gmail-Id@gmail.com', 'Metropolis Delhi');
$mail->Subject ="Email Subject";
$mail->Body =$body;
if(!$mail->Send())
{
echo $mail->ErrorInfo;
return false;
}
else
{
echo "Email Sent to !". $collname;
}
?>
"The following From address failed: your@gmail.com"
Below was my source code :
<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$body="email body \n";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "your-gmail-Id@gmail.com"; // GMAIL username
$mail->Password = "gmail password"; // GMAIL password
$mail->SetFrom('your-gmailid@gmail.com', 'Metropolis Delhi');
$mail->AddReplyTo('your-gmailid@gmail.com', 'Metropolis Delhi');
$mail->Subject ="Email Subject";
$mail->Body =$body;
if(!$mail->Send())
{
echo $mail->ErrorInfo;
return false;
}
else
{
echo "Email Sent to !". $collname;
}
?>
To solve this problem, First I login to gmail and go to ''setting' => Account and Import => update correct "Send mail as" i.e. correct "From name" and email.
But problem is still not solved.
Now I change ssl to tls and port no 587 in my code.
Now it is working fine. Below is code which is working fine.
<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$body="email body \n";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "your-gmail-Id@gmail.com"; // GMAIL username
$mail->Password = "your-password"; // GMAIL password
$mail->FromName="From Name"; // correct from name
$mail->From="your-gmailId@gmail.com";
$mail->AddReplyTo('your-gmail-Id@gmail.com', 'Metropolis Delhi');
$mail->Subject ="Email Subject";
$mail->Body =$body;
if(!$mail->Send())
{
echo $mail->ErrorInfo;
return false;
}
else
{
echo "Email Sent to !". $collname;
}
?>
No comments:
Post a Comment