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

我是 PHP 新手,我必须使用 phpmailer 发送简历。我发现错误为“Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting ”。请更改代码。我在我的代码中使用 phpmailer。它在我第一次做的时候有效,但现在这段代码会出错。


<?php 


include('header.php');

require 'PHPMailerAutoload.php';

$message='';


if(isset($_POST["submit"]))

{

   $path='upload/'.$_FILES["resume"]["name"];

   move_uploaded_file($_FILES["resume"]["tmp_name"], $path);


   $mail = new PHPMailer;


$mail->SMTPDebug = 0;                               // Enable verbose debug output


$mail->isSMTP();                                      // mailer to use SMTP

$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers

$mail->SMTPAuth = true;                               // Enable SMTP authentication

$mail->Username = 'xyz01@gmail.com';                 // SMTP username

$mail->Password = 'mypasswordgoeshere';                           // SMTP password

$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted

$mail->Port = 465;                                    // TCP port to connect to


$mail->From=$_POST['email'];

$mail->FromName=$_POST['name'];

$mail->setFrom($_POST['email']);

$mail->addAddress('xyz01@gmail.com'); 


$mail->AddCC($_POST['name'],$_POST['email']);


$mail->WordWrap=50;


$mail->AddAttachment($path);


$mail->Subject='application for job';

    // Add a recipient

              // Name is optional

$mail->addReplyTo($_POST['email']);


$mail->isHTML(true);                                  // Set email format to HTML


//$mail->Subject = $_POST['subject'];

$mail->Body    = $_POST['message'];

$mail->AltBody = $_POST['message'];




if(!$mail->send()) {

    echo '<script>alert("Message could not be sent.")</script>';

    echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {

    echo '<script>alert("Message has been sent");


        window.location.href="career.php";

    </script>';


}



}


?>



烙印99
浏览 975回答 2
2回答

白猪掌柜的

从代码中删除或评论$mail->isSMTP();,然后重试!或者在代码中检查您的用户名和密码。

白衣非少年

您是否通过更改安全性较低的应用访问权限并打开它来更改您的 gmail 安全设置
打开App,查看更多内容
随时随地看视频慕课网APP