我需要帮助用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中启用不太安全的应用程序的权限来解决此问题