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

joh*_*dad 9 php gmail smtp phpmailer

我已经尝试在StackOverflow和其他网站上发布了每个单独的脚本/代码/方法,但没有运气.我在GoDaddy上主持.我已经设置了一个Google App帐户,设置了MX Records所需的一切(使用GoDaddy工具),甚至尝试从我的网站的GMAIL界面发送一些电子邮件,以及通过我的一个unix上的终端中的SMTP发送电子邮件机器.这一切都奏效了.

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

我总是收到:

SMTP - >错误:无法连接到服务器:连接被拒绝(111)SMTP错误:无法连接到SMTP主机.邮件程序错误:SMTP错误:无法连接到SMTP主机.

这是我用于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>
Run Code Online (Sandbox Code Playgroud)

谢谢!

Cha*_*les 23

如前所述,众所周知,GoDaddy会阻止传出的SSL SMTP连接,有利于强制您使用自己的外发邮件服务器.

对于GoDaddy作为公司,注册商和网络主机的巨大自负,这几乎是冰山一角.Ditch'em.

  • 刚刚通过GoDaddy的客户支持证实了这一点; 多么糟糕的服务. (7认同)

eca*_*rol 7

我有同样的问题,经过不同的网站后,我找到了这个,它确实有效!

GoDaddy 允许使用Gmail作为您的SMTP发送电子邮件,只需要摆脱smtp.gmail.com并使用他们的主机.这是我的设置:

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account@gmail.com";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...
Run Code Online (Sandbox Code Playgroud)

参考(参见前两篇文章) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

  • 根据定义使用*他们的*SMTP服务器**不是**使用Gmail的SMTP服务器.将电子邮件作为您的Gmail地址(或Google Apps地址)发送可能会出现严重的垃圾邮件问题,因为他们的服务器不会被SPF或DKIM清除,因为您的Gmail用户帐户会被发送. (7认同)

小智 6

我终于解决了这个问题,并在线发表了评论//$mail->isSMTP();。之后我的 Gmail 帐户开始在 Godaddy 中正常工作。

require 'PHPMailer/class.phpmailer.php';
require 'PHPMailer/PHPMailerAutoload.php';


$mail = new PHPMailer;


 $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $subject = 'Your subject';

    $body = "From: $name\n E-Mail: $email\n Comments:\n $message";


//$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'xxxxxxxxxxxx@gmail.com';
$mail->Password = 'xxxxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port =587;
Run Code Online (Sandbox Code Playgroud)

  • 这不是“修复”;而是“修复”。它通过不使用您的 Gmail 帐户来使您的 Gmail 帐户“正常工作”。 (4认同)