0
消息無法sent.Mailer錯誤:SMTP連接()失敗消息無法sent.Mailer錯誤
<?php
include('libs/PHPMailer-master/PHPMailerAutoload.php');
//require 'PHPMailerAutoload.php';
//require 'system/includes/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = gethostbyname("hostName"); // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = '[email protected]'; // SMTP username
//$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom([email protected], 'Mailer');
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
//$mail->addAddress('[email protected]'); // Name is optional
//$mail->addReplyTo('[email protected]', 'Information');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
這是我的代碼發送電子郵件。但它給了我一個錯誤「消息無法sent.Mailer錯誤:SMTP連接()失敗https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting。」有人知道它的原因嗎?
你可以找到這個答案有幫助: https://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server –
我看到2可能的原因:您的託管鎖傳出connexion在端口587或您的憑據到您的SMTP不正確。爲什麼'$ MAIL-> Username'和'$ MAIL-> password'的評論?你有沒有試過去掉這一兩行並輸入您的正確的憑據?如果您的SMTP提供商不需要憑證,你可能需要設置'$ MAIL-> SMTPAuth'到'FALSE' – Fabien
我註釋掉了兩行設置的值。我仍然得到同樣的錯誤。 – sj111