我需要用 PHP 发送电子邮件方面的帮助。我实际上正在尝试使用 PHP 邮件程序发送电子邮件。不知何故,某些邮件 ID 能够发送电子邮件,但某些其他电子邮件 ID 无法发送。我在 gmail 中收到一封电子邮件,内容为“已阻止登录尝试”。有人可以帮我知道我需要在哪里更改我的 gmail 帐户中的设置才能使我的 PHP 代码发送电子邮件吗?
require("phpmailer/class.PHPMailer.php");
require("phpmailer/class.smtp.php");
$f_pointer=fopen("test.csv","r"); // file pointer
$emails = array();
while (($data = fgetcsv($f_pointer, 1000, ",")) !== FALSE) {
$num = count($data);
$emails[] = $data[1];
}
foreach($emails as $key=>$val){
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "tls://smtp.gmail.com:587"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "abc"; // SMTP username
$mail->Password = "some password"; // SMTP password
$mail->From = "abc@gmail.com";
$mail->FromName = "abc";
$mail->AddAddress($val);
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
}
这对于某些示例“abc@gmail.com”来说工作正常,但是当我使用其他用户名、密码和电子邮件说“xyz@gmail.com”时,我在收件箱中收到一封电子邮件,说明“登录尝试失败”。帮助表示赞赏。
最佳答案
已通过在链接 https://www.google.com/settings/security/lesssecureapps 中打开安全性较低的应用程序的权限来解决此问题。
关于php - 在 gmail 中通过 PHP 登录时电子邮件尝试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33630263/