邮件程序错误:SMTP连接()失败?

时间:2017-12-07 07:32:07

标签: php

我在php邮件程序中遇到有关SMTP连接的问题,这是我的代码

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function

//Load composer's autoloader
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
    //Server settings

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'mine@gmail.com';                 // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('mine@gmail.com', 'mine');
    $mail->addAddress('mine@gmail.com', 'mine');     // Add a recipient
    $mail->addReplyTo('mine@gmail.com', 'mine');
    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = $_POST['name'];
    $mail->Body    = $_POST['mail']."<br>" .$_POST['phn']."<br>".$_POST['des'];
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';echo "<br>";`enter code here`
    echo "<a href=index.html>Go Back";
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}

?>

实际上这段代码运行得很好,而且我收到了邮件,但现在它无法正常工作,并说邮件程序错误:SMTP连接()失败这是一个错误。帮帮我!!!

...谢谢

0 个答案:

没有答案