加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

GoDaddy Linux上的PHP共享尝试通过GMAIL SMTP发送

发布时间:2020-12-14 00:22:57 所属栏目:Linux 来源:网络整理
导读:我已尝试在StackOverflow和其他网站上发布的每个单独的脚本/代码/方法,但没有运气.我在GoDaddy上主持.我已经设置了一个Google App帐户,设置了MX Records所需的一切(使用GoDaddy工具),甚至尝试从我的网站的GMAIL界面发送一些电子邮件,以及通过我的一个unix上
我已尝试在StackOverflow和其他网站上发布的每个单独的脚本/代码/方法,但没有运气.我在GoDaddy上主持.我已经设置了一个Google App帐户,设置了MX Records所需的一切(使用GoDaddy工具),甚至尝试从我的网站的GMAIL界面发送一些电子邮件,以及通过我的一个unix上的终端中的SMTP发送电子邮件机器.这一切都奏效了.

但是,当我尝试使用PHP时,却没有!难道GoDaddy会以某种方式阻止它吗?

我总是收到:

SMTP -> ERROR: Failed to connect to
server: Connection refused (111) SMTP
Error: Could not connect to SMTP host.
Mailer Error: SMTP Error: Could not
connect to SMTP host.

这是我用于PHPMailer的代码:

<html>
    <head>
        <title>PHPMailer - SMTP (Gmail) advanced test</title>
    </head>
    <body>
    <?php
    require_once('../class.phpmailer.php');
    //include("class.smtp.php"); // optional,gets called from within class.phpmailer.php if not already loaded

    $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

    try {
        $mail->Host       = "smtp.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->Username   = "MYFROMADDRESSHERE";  // GMAIL username
        $mail->Password   = "MYFROMPASSWORDHERE";            // GMAIL password
        $mail->AddReplyTo('MYFROMADDRESSHERE','Sender Name');
        $mail->AddAddress('TESTTOADDRESSHERE','Recipient Name');
        $mail->SetFrom('MYFROMADDRESSHERE','Sender Name');
        $mail->AddReplyTo('MYFROMADDRESSHERE','Sender Name');
        $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(file_get_contents('contents.html'));
        $mail->AddAttachment('images/phpmailer.gif');      // attachment
        $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
        $mail->Send();
        echo "Message Sent OK</p>n";
    } catch (phpmailerException $e) {
        echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
        echo $e->getMessage(); //Boring error messages from anything else!
    }
    ?>
</html>

谢谢!

解决方法

如前所述,GoDaddy has been known to block outgoing SSL SMTP connections赞成强制您使用自己的外发邮件服务器.

对于GoDaddy作为公司,注册商和网站主持人的巨大骄傲,这几乎是冰山一角. Ditch’em.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读