我使用phpmailer()概念使用php脚本从共享服务器向用户发送邮件,但根据phpmailer代码,即使脚本中的所有内容都正确,我也无法发送邮件。
我的代码如下:
$message = " This is testing message from my server";
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "moorthi.mrk10@gmail.com"; // My gmail username
$mail->Password = "************"; // My Gmail Password
$mail->SetFrom("moorthi.mrk10@gmail.com");
$mail->Subject = "Test Mail from my Server";
$mail->Body = $message;
$mail->AddAddress($email);
if($mail->Send())
{
print json_encode("SUCCESS");
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}注意:我使用“GMail”作为服务器,SMTPSecure为“ssl”,端口为"465“,用户名和密码为GMail用户名和密码。
我使用了VPS共享服务器,并在该服务器上保留了我的php脚本。
我认为我的php脚本没有问题,我不知道为什么它不能工作。
,我得到了这样的错误。
2014-02-21 12:30:11 CLIENT -> SERVER: EHLO jkcorporates.com
2014-02-21 12:30:11 CLIENT -> SERVER: AUTH LOGIN
2014-02-21 12:30:11 CLIENT -> SERVER: bW9vcnRoaS5tcmsxMEBnbWFpbC5jb20=
2014-02-21 12:30:11 CLIENT -> SERVER: OTk0MTI0MTE0MA==
2014-02-21 12:30:11 SMTP ERROR: Password command failed: 534-5.7.14
534-5.7.14 i-_eumA> Please log in via your web browser and then try again.
534 5.7.14 54 k76sm17979938yho.18 - gsmtp
2014-02-21 12:30:11 CLIENT -> SERVER: QUIT
" The ERROR is " SMTP connect() failed.请给出一些解决办法。
提前谢谢。
记住:我使用共享服务器名'VPS.mydomain.com‘,我想使用GMail作为我的SMTP服务器向用户发送邮件。
发布于 2014-08-07 06:02:33
有点晚了,但也许有人会发现它有用。
修复问题的链接(您必须登录到google ):
https://security.google.com/settings/security/activity?hl=en&pli=1
https://www.google.com/settings/u/1/security/lesssecureapps
https://accounts.google.com/b/0/DisplayUnlockCaptcha
对所发生的事情的一些解释:
这个问题可能是由于“不太安全”的应用程序试图使用电子邮件帐户(根据谷歌帮助( google help ),不确定它们如何判断什么是安全的,什么是不安全的),或者如果您试图连续登录几次,或者如果您更改了国家(例如使用VPN,将代码移动到不同的服务器,或者实际上尝试从不同的地方登录)。
为了解决这个问题,我不得不:(第一次)
这是第一次工作,但几个小时后,可能是因为我做了大量的测试,问题再次出现,并没有固定使用上述方法。此外,我还必须清除captcha (有趣的图片,它要求您在当前多次登录任何帐户时重写一个单词或句子):
希望这能有所帮助。
发布于 2015-01-16 11:18:07
用这个:
https://www.google.com/settings/u/1/security/lesssecureapps
https://accounts.google.com/b/0/DisplayUnlockCaptcha
https://security.google.com/settings/security/activity?hl=en&pli=1此链接允许访问google帐户。
更新19-05-2017:
这些url你必须访问从IP地址,将发送电子邮件。
发布于 2014-09-04 16:31:40
解决了问题-- PHPMailer - SMTP错误:从我的服务器发送邮件时密码命令失败
require_once('class.phpmailer.php');
include("class.smtp.php");
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$messageField = $_POST['message'];
$phoneField = $_POST['contactno'];
$cityField = $_POST['city'];
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$body .= $nameField;
try {
//$mail->Host = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->Username = "xxxxx@gmail.com"; // GMAIL username
$mail->Password = "********"; // GMAIL password
$mail->AddAddress('sendto@gmail.com', 'abc');
$mail->SetFrom('xxxxxx@gmail.com', 'def');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
echo "Message Sent OK</p>\n";
header("location: ../test.html");
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}重要信息:
转到google设置,做“不那么安全”的应用程序启用。看起来不错。对我起作用了。
https://stackoverflow.com/questions/21937586
复制相似问题