我需要用 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 = "[email protected] /cdn-cgi/l/email-protection";
$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";
}
这对于某些示例来说效果很好'[电子邮件受保护] /cdn-cgi/l/email-protection',但是当我使用其他用户名、密码和电子邮件时说'[电子邮件受保护] /cdn-cgi/l/email-protection”我的收件箱中收到一封电子邮件,指出“登录尝试失败”。帮助表示赞赏。
已通过在链接中打开不太安全的应用程序的权限来解决此问题https://www.google.com/settings/security/lesssecureapps https://www.google.com/settings/security/lesssecureapps
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)