SMTP错误:无法连接到SMTP主机。失败

时间:2017-07-14 11:27:21

标签: php email phpmailer

我在通过php邮件发送邮件时遇到问题,我很容易在localhost(Wampp)上发送电子邮件,但在直播服务器上我收到错误:

  

SMTP错误:无法连接到SMTP主机。失败

 <?php 
    if (isset($_POST['submit'])) {
      # code...
    $customeremail="*************";

    $message=
    'Full Name: '.$_POST['name'].'<br />
    Subject:    '.$_POST['subject'].'<br />

    Phone:  '.$_POST['phone'].'<br />
    Email:  '.$_POST['email'].'<br />
    Comments:   '.$_POST['message'].'
    ';
    require "phpmailer/class.phpmailer.php"; //include phpmailer class

    // Instantiate Class
    $mail = new PHPMailer();

    // Set up SMTP
    $mail->IsSMTP();                // Sets up a SMTP connection
    $mail->SMTPAuth = true;         // Connection with the SMTP does require authorization
    $mail->SMTPSecure = "ssl";      // Connect using a TLS connection
    $mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
    $mail->Port = 465;  //Gmail SMTP port
    $mail->Encoding = '7bit';

    // Authentication
    $mail->Username   = "******"; // Your full Gmail address
    $mail->Password   = "******"; // Your Gmail password

    // Compose
    $mail->From = "*************";
    $mail->FromName = "**********";

    $mail->Subject = "DRIVER AND CAR DETAILS";      // Subject (which isn't required)
    $mail->MsgHTML($message);

    // Send To
    $mail->AddAddress($customeremail, "Recipient Name"); // Where to send it - Recipient
    $result = $mail->Send();        // Send!



    if(!$mail->Send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent.';
    }
    ?>

我尝试创建一个php.ini文件并放置extension=php_openssl.dll但它也不起作用,还有我的其他网站,但我只是在这里收到错误,请帮助我!!

0 个答案:

没有答案