1

PHPmailer 在 localhost 中工作正常,但在服务器上显示 SMTP 错误,以前它工作但很好,但最近它不工作。这个问题出现在我所有的 cPanel 中,可能是经销商帐户服务器问题吗?我正在使用下面的代码,我收到如下错误:SMTP 错误:无法验证。

function mail_sending($to_address, $to_name, $title_tag, $subject_tag, $mail_body) 
{
    $mail = new PHPMailer();
    //End Code for adding a Page
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPAuth = true;                    // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                   // sets the prefix to the servier
    $mail->Host = "myhost.com";        // sets  the SMTP server
    $mail->Port = 465;                     // set the SMTP port
    $mail->Username = "admin@myhost.com";   // username
    $mail->Password = "password";

    $mail->SetFrom('admin@myhost.com', $title_tag);

    $mail->Subject = $subject_tag;

    //End Attachments
    //Start code for sending a html Body
    $mail->IsHTML(true);
    $mail->Body = $mail_body;
    //End code for sending a html Body
    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; 
    $mail->AddAddress($to_address, $to_name);

    $mail->Send();
}
4

2 回答 2

0

从错误消息看来,本地服务器在让您发送任何邮件之前需要身份验证信息。

您可以像这样指定所述信息:

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “email@domain.com”; // SMTP username
$mail->Password = “password”; // SMTP password

username并且password应该是您从托管服务提供商那里获得的关于 smtp 使用的信息,我相信他们有常见问题解答或可以帮助您。

于 2012-10-15T17:44:56.270 回答
0

确保在您的服务器中启用了 OpenSSL:

1. Login through WHM with your root account;
2. Select or search for "EasyApache (Apache Update)";
3. Select "Start customizing based on profile";
4. Select "Next step";
5. Select "Next step";
6. Select "Next step";
7. Select "Exhaustive Options List";
8. Select "OpenSSL";
9. Select "Save and Build" and choose "Yes" in the following questions.

更多信息:http ://forums.cpanel.net/f5/enable-php-openssl-machine-whm-cpanel-222991.html

于 2012-10-15T17:49:28.187 回答