phpmailer 从任何 gmail 发送电子邮件
phpmailer to send email from any gmail
我在 phpmailer class 中使用了以下代码片段,以便在我的 Web 应用程序中提交表单时使用 gmail 服务器发送电子邮件!虽然它适用于我的个人 gmail 地址,但当我用我的客户 gmail 地址和密码替换我的 gmail 地址和密码时,它不会发送电子邮件!
我该如何纠正这个问题?
require "phpmailer/class.phpmailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "sunethperera@gmail.com"; // Your full Gmail address
$mail->Password = "******"; // Your Gmail password
// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "Pharmacy order confirmaton"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress($_POST["Email"], "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
当我从客户的电子邮件发送消息时,收到错误消息:
SMTP Error: Could not authenticate.
我该如何解决这个问题?
尝试使用这个:
$mail->SMTPSecure = "tls";
删除编码参数
还要检查您的发件人地址和密码是否正确。
立即更新您的 PHPMailer。你是 运行 一个旧的易受攻击的版本。阅读故障排除指南并按其说明进行操作。不要使用提交者的地址作为发件人地址 - 它是伪造的,会使您无法通过 SPF 检查。 Gmail 不允许您从任意地址发送邮件。您的身份验证问题已在指南中介绍,但您需要在 Gmail 中启用安全性较低的应用程序,或实施 oauth,如文档和示例中所述。
这已经在 SO 上多次提及 - 在你之前搜索 post。
我在 phpmailer class 中使用了以下代码片段,以便在我的 Web 应用程序中提交表单时使用 gmail 服务器发送电子邮件!虽然它适用于我的个人 gmail 地址,但当我用我的客户 gmail 地址和密码替换我的 gmail 地址和密码时,它不会发送电子邮件!
我该如何纠正这个问题?
require "phpmailer/class.phpmailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "sunethperera@gmail.com"; // Your full Gmail address
$mail->Password = "******"; // Your Gmail password
// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "Pharmacy order confirmaton"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress($_POST["Email"], "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
当我从客户的电子邮件发送消息时,收到错误消息:
SMTP Error: Could not authenticate.
我该如何解决这个问题?
尝试使用这个:
$mail->SMTPSecure = "tls";
删除编码参数
还要检查您的发件人地址和密码是否正确。
立即更新您的 PHPMailer。你是 运行 一个旧的易受攻击的版本。阅读故障排除指南并按其说明进行操作。不要使用提交者的地址作为发件人地址 - 它是伪造的,会使您无法通过 SPF 检查。 Gmail 不允许您从任意地址发送邮件。您的身份验证问题已在指南中介绍,但您需要在 Gmail 中启用安全性较低的应用程序,或实施 oauth,如文档和示例中所述。
这已经在 SO 上多次提及 - 在你之前搜索 post。