我用DigitalOcean用Ubuntu构建了一个液滴,并试图将其配置为使用SMTP发送电子邮件。
我知道DigitalOcean会阻止IPv6上的SMTP,但不会阻止IPv4,所以我禁用了IPv6,就像这篇文章所说的那样。
我的剧本仍然不起作用。我试过使用端口25、465和587。TLS和SSL。
我已经为Ubuntu 14.04安装了sendmail
,但无法正常工作。
这是我的脚本:
<?php
require 'mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$to = $_GET['email'];
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'rafawins@gmail.com';
$mail->Password = '***';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('rafawins@gmail.com', 'Rafael');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'Subject';
$contents = ob_get_contents();
$mail->Body = "ao!";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
print_r(error_get_last());
?>
出现的错误为:
SMTP连接()失败。
我有兴趣使用SMTP发送电子邮件,所以需要->isSMTP()
!
我哪里错了?
非常感谢。
编辑:
执行:telnet smtp.gmail.com 587
我得到:
正在尝试74.125.133.108…
已连接到gmail-smtp-msa.l.google.com.
转义符为"^]"。
220 smtp.gmail.com ESMTP w6sm13897014wjy.31-gsmtp
做:openssl s_client -connect smtp.gmail.com:465
我也得到了答案。。。
怎么了?
小心从不同设备使用Gmail。谷歌不允许并立即屏蔽一个不应该使用的账户所在的位置(当然在谷歌看来)。
在使用SMTP发送邮件的实时服务器上,Do it。
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
和Comment$mail->IsSMTP();
它对我有用…
试着注释掉第8行。
// $mail->isSMTP();