在Gmail中通过PHP登录时,电子邮件尝试失败 [英] Email Attempt Failed when signin through PHP in gmail

查看:165
本文介绍了在Gmail中通过PHP登录时,电子邮件尝试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要PHP中的电子邮件发送帮助。我实际上是试图使用PHP邮件发送电子邮件。某种程度上,某些邮件ID能够发送电子邮件,但对于某些其他电子邮件ID无法发送。我在gmail收到一封电子邮件,声明'Signin attempt prevent。'有人能帮我知道我需要在哪里更改我的gmail帐户中的设置才能让我的PHP代码发送电子邮件?

  require(phpmailer / class.PHPMailer.php); 
require(phpmailer / class.smtp.php);
$ f_pointer = fopen(test.csv,r); //文件指针
$ emails = array(); ($ data = fgetcsv($ f_pointer,1000,,))!== FALSE){
$ num = count($ data);

$ emails [] = $ data [1];
}
foreach($ emails as $ key => $ val){
$ mail = new PHPMailer();

$ mail-> IsSMTP(); //设置邮件使用SMTP
$ mail-> Host =tls://smtp.gmail.com:587; //指定主服务器和备份服务器
$ mail-> SMTPAuth = true; //打开SMTP认证
$ mail->用户名=abc; // SMTP用户名
$ mail->密码=某个密码; // SMTP密码

$ mail-> From =abc@gmail.com;
$ mail-> FromName =abc;
$ mail-> AddAddress($ val);

$ mail-> Subject =这是主题;
$ mail-> Body =这是HTML邮件正文< b>加粗!< / b>;
$ mail-> AltBody =这是非HTML邮件客户端的纯文本正文;

if(!$ mail-> Send())
{
echo无法发送消息。< p>;
回显邮件错误:。 $ MAIL-> ERRORINFO;
出口;
}

echo消息已发送;
}

这对于一些例子'abc@gmail.com'来说工作正常,但当我使用其他用户名,密码和电子邮件说'xyz@gmail.com'我收到我的邮箱中的邮件,说明'登录尝试失败'。帮助表示赞赏。 解决方案已通过打开链接 https://www.google.com/settings/security/lesssecureapps


I need a help in email sending in PHP. Am actually trying to send email using PHP mailer. Somehow for some of the mail ids am able to send the email but for some other email ids am unable to send. I receive an email in gmail stating 'Signin attempt prevented.' Can somebody help me know where do I need to change the settings in my gmail account in order to make my PHP code to send emails?

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";
}

This is working fine for some example 'abc@gmail.com', but when I use other username, password and email say 'xyz@gmail.com' I receive an email in my inbox stating 'signin attempt failed.' Help appreciated.

解决方案

It has been resolved by turning on the permission for less secure apps in the link https://www.google.com/settings/security/lesssecureapps

这篇关于在Gmail中通过PHP登录时,电子邮件尝试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆