PHPMailer 无法在我的服务器上工作 [英] PHPMailer not working in my server

查看:52
本文介绍了PHPMailer 无法在我的服务器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Ubuntu 和 DigitalOcean 构建了一个 Droplet,我正在尝试将其配置为使用 SMTP 发送电子邮件.

I built a droplet with Ubuntu with DigitalOcean and I'm trying to configure it to send emails with SMTP.

我知道 DigitalOcean 通过 IPv6 但不会通过 IPv4 阻止 SMTP,所以我禁用了 IPv6 作为 这篇文章说.

I know DigitalOcean blocks SMTP over IPv6 but not over IPv4 so I disabled IPv6 as this post says.

我的脚本仍然不起作用.我尝试过端口 25、465 和 587.TLS 和 SSL.

My script still doesn't work. I've tried with ports 25, 465 and 587. TLS and SSL.

我已经为 Ubuntu 14.04 安装了 sendmail 但没有工作.

I've installed sendmail for Ubuntu 14.04 but not working.

这是我的脚本:

<?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 connect() 失败.

SMTP connect() failed.

我对使用 SMTP 发送电子邮件感兴趣,所以 ->isSMTP() 是必需的!

I'm interested in sending email using SMTP so ->isSMTP() is required!

我哪里错了?

非常感谢.

正在做:telnet smtp.gmail.com 587我得到:

正在尝试 74.125.133.108...

Trying 74.125.133.108...

已连接到 gmail-smtp-msa.l.google.com.

Connected to gmail-smtp-msa.l.google.com.

转义字符是'^]'.

220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp

220 smtp.gmail.com ESMTP w6sm13897014wjy.31 - gsmtp

并且正在做:openssl s_client -connect smtp.gmail.com:465 我也得到了答案......

and doing: openssl s_client -connect smtp.gmail.com:465 I get an answer as well...

怎么了?

推荐答案

注意在不同设备上使用 Gmail.谷歌不允许并立即阻止使用帐户的位置不应该使用的位置(当然在谷歌眼中).

Beware of using Gmail from different devices. google doesn't allow and block immediately a location from where an account is used where it isn't supposed to use (in the eyes of google ofcourse).

这篇关于PHPMailer 无法在我的服务器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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