在Gmail中通过PHP登录时,电子邮件尝试失败

编程入门 行业动态 更新时间:2024-10-09 16:25:24
本文介绍了在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:587; //指定主服务器和备份服务器 $ mail-> SMTPAuth = true; //打开SMTP认证 $ mail->用户名=abc; // SMTP用户名 $ mail->密码=某个密码; // SMTP密码 $ mail-> From =abc@gmail; $ 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'来说工作正常,但当我使用其他用户名,密码和电子邮件说'xyz@gmail'我收到我的邮箱中的邮件,说明'登录尝试失败'。帮助表示赞赏。 解决方案已通过打开链接 www.google/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: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"; $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', but when I use other username, password and email say 'xyz@gmail' 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 www.google/settings/security/lesssecureapps

更多推荐

在Gmail中通过PHP登录时,电子邮件尝试失败

本文发布于:2023-11-09 23:22:55,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   Gmail   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!