Centos Webpanel SMTP

时间:2018-09-20 15:20:08

标签: php centos smtp centos7 vps

我已经安装了centos Web面板并进行了所有设置。有两个网站托管。当我尝试使用PHPmailer发送电子邮件时。有一个错误。

2018-09-20 15:15:10 CLIENT -> SERVER: EHLO localhost
2018-09-20 15:15:10 SERVER -> CLIENT: 250-vps203527.vps.ovh.ca250-PIPELINING250-SIZE 204800000250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2018-09-20 15:15:10 CLIENT -> SERVER: STARTTLS
2018-09-20 15:15:11 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2018-09-20 15:15:11 CLIENT -> SERVER: QUIT
2018-09-20 15:15:11 
2018-09-20 15:15:11 
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
2018-09-20 15:15:10 SERVER -> CLIENT: 220 vps203527.vps.ovh.ca ESMTP Postfix

$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 2;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'vps203527.vps.ovh.ca';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'admin@  .com';                 // SMTP username
    $mail->Password = '';                           // SMTP password
    $mail->SMTPSecure = false;                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 25;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('admin@.com', 'Test Mail');
    $mail->addAddress('@gmail.com', 'Joe User');     // Add a recipient

    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}

这是我使用的php代码

1 个答案:

答案 0 :(得分:2)

您正面临问题,因为您在PHP脚本中输入了错误的主机值。请在主机字段[$ mail-> Host ='vps203527.vps.ovh.ca';]中输入您的SMTP服务器名称。它应该像mail.yourdomainname.com

我也遇到了相同的错误,并使用以下代码修复了该错误。

以下是通过SMTP身份验证从PHP脚本发送电子邮件的示例代码:

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                // send via SMTP
$mail->Host     = "smtp.domain.com"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "email@domain.com";   // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From     = "email@domain.com";
$mail->FromName = "Name";
$mail->AddAddress("Recipient@emailaddress.com","Name");
$mail->AddReplyTo("yourname@domain.com","Your Name");

$mail->WordWrap = 50;                 // set word wrap

$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the <b>HTML body</b>";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

?>

Please make sure that you make the changes in the above script as necessary. 

Note: You should always verify the email address before sending an email campaign.

如果您遇到任何问题,请告诉我。我会尝试修复它。

谢谢!