【问题标题】:Php Mailer error - Godaddy SmtpPhp Mailer 错误 - Godaddy Smtp
【发布时间】:2016-08-18 20:26:08
【问题描述】:

我有一个项目,我必须向用户发送 100-200 封邮件,但每封邮件对每个用户都有不同的令牌。我在 godaddy 上托管了电子邮件。

所以我希望使用 phpmailer 发送电子邮件。下面是我正在测试的脚本,但它一直给我这个错误 -

SMTP 错误:无法连接到服务器:连接被拒绝 (111) SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 邮件程序错误:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

<?php

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require 'mailm/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug   = 2;
$mail->DKIM_domain = '127.0.0.1';
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host        = "smtpout.secureserver.net";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port        = 465;
//Whether to use SMTP authentication
$mail->SMTPAuth    = true;
//Username to use for SMTP authentication
$mail->Username    = "itsupport@mysite.ae";
//Password to use for SMTP authentication
$mail->Password    = "Mypassword";
$mail->SMTPSecure  = 'ssl';
//Set who the message is to be sent from
$mail->setFrom('itsupport@mysite.ae', 'IT Helpdesk');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('sgajara@gmail.com', 'IT Helpdesk');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//Replace the plain text body with one created manually
$mail->Body = 'This is a plain-text message body';
//Attach an image file


//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>

这个脚本是我在博客上找到的。

也欢迎任何替代方案,我的目的是从我的 godaddy 电子邮件帐户发送 200 封电子邮件,但每封电子邮件都有一个单独的令牌,该令牌从数据库中获取,然后插入邮件正文并发送给用户。

【问题讨论】:

  • 但在我看来问题与具体代码无关,但与“SMTP 授权”有关。您如何确保建立 SMTP 连接并正确设置邮件服务器?
  • 除了 GoDaddy 身份验证问题,您的代码基于 the mailing list example provided wth PHPMailer

标签: php email phpmailer


【解决方案1】:

就是这么简单:

您必须专注于 smtp 主机、端口、ssl... 将 smtp 主机更改为:relay-hosting.secureserver.net 并删除端口和ssl,仅此而已... 不要使用smtp端口和smtp ssl真假...

    var fromAddress = "mailfrom@yourdomain";
    // any address where the email will be sending
    var toAddress = "mailto@yourdomain";
    //Password of your mail address
    const string fromPassword = "******";
    // Passing the values and make a email formate to display
    string subject = TextBox1.Text.ToString();
    string body = "From: " + TextBox2.Text + "\n";
    body += "Email: " + TextBox3.Text + "\n";
    body += "Subject: " + TextBox4.Text + "\n";
    body += "Message: \n" + TextBox5.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "relay-hosting.secureserver.net";
**//Warning Delete =>//smtp.Port = 80;**
**//Warning Delete =>//smtp.EnableSsl = false;**
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);

【讨论】:

    【解决方案2】:

    您需要修改下面提到的一些配置。让我知道这是否有效。

    $mail->Host = 'localhost';
    $mail->Port = 25;  
    $mail->ssl = false;
    $mail->authentication = false;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-17
      • 1970-01-01
      • 2017-07-03
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 2018-01-18
      相关资源
      最近更新 更多