PHPMailer在Localhost上工作,但在Server上不工作,为什么?

时间:2018-07-31 06:22:29

标签: php mysqli

1 个答案:

答案 0 :(得分:0)

似乎您可能有邮件配置问题。可以与以下内容匹配

    <?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
            try {
    //Server settings
    $mail->SMTPDebug = 0;                                 // Enable verbose debug output
    $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 = 'youremail@gmail.com';                 
    $mail->Password = 'password';                          
    $mail->SMTPSecure = 'tls';                            
    $mail->Port = 587;                                    
    //Recipients
    $mail->setFrom('youremail@gmail.com', 'youremail@gmail.com');
    $mail->addAddress("receiver@gmail.com", "name");     
    //Content
    $mail->isHTML(true);                                 
    $mail->Subject = 'Account Activation';
    $mail->Body    = "sldkfjsldfjsldkfj";
    $mail->AltBody = "fkjsldfjslfs";
    $mail->send();
    echo "sent";
} catch (Exception $e) {
    echo $e;
    echo 'Message could not sent for verification.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>