3

我需要在 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”时,我在收件箱中收到一封电子邮件,说明“登录尝试失败”。帮助表示赞赏。

4

1 回答 1

10

它已通过在链接https://www.google.com/settings/security/lesssecureapps中打开不太安全的应用程序的权限来解决

于 2015-11-12T08:36:21.943 回答