【发布时间】:2016-04-14 10:30:16
【问题描述】:
如何让 gmail 接受来自 localhost 的 phpmailer 并且不阻止登录?
我该如何解决这个错误信息
无法发送邮件。Mailer 错误:SMTP connect() 失败。
<?php
require 'PHPMailer-master\PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'my@gmail.com'; // SMTP username
$mail->Password = 'valid'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('my@gmail.com', 'me');
// Add a recipient
$mail->addAddress('their@gmail.com'); // Name is optional
$mail->addReplyTo('my@gmail.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->isHTML(true); // Set email format to HTML
$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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
【问题讨论】:
-
你试过25端口吗?
-
你的 PHP 版本是什么 ..?
-
你也可以试试端口 465 SSL support.google.com/a/answer/176600?hl=en
-
我只使用谷歌商业应用程序完成了这项工作。个人帐户也适用于此吗?