PHPMailer不发送邮件

时间:2018-05-22 06:49:57

标签: php email smtp

伙计我在这个问题上已经阅读了很多答案,但问题仍然存在。 PHPMailer不发送给出以下错误的电子邮件。

邮件程序错误:SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

以下是代码:

date_default_timezone_set('Etc/UTC');

require 'PHPMailer-master/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.domain.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port =25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
//Username to use for SMTP authentication
$mail->Username = "mail@mail.com";
//Password to use for SMTP authentication
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom("mail@mail.com","Contact Form");
//Set an alternative reply-to address
$mail->addReplyTo($_POST['user_mail'], $_POST['user_name']);
//Set who the message is to be sent to
$mail->addAddress("mail@mail.com", "Contact Form");
//Set the subject line
$mail->Subject = $_POST['subject'] . " - Contact Form";
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("Message from ". $_POST['user_name']." : <br/>".$_POST['message'] . "<br/> Contact Details : <br/> Email :" . $_POST['user_mail'] . "<br/> Contact Number : " . $_POST['user_number']);
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "<script>window.location.href='thankyou.html';</script>";
}

0 个答案:

没有答案