2017-08-01 61 views
0
<?php 

require_once "vendor/autoload.php"; 

$mail = new PHPMailer;  
$mail->SMTPDebug = 0;         
$mail->isSMTP();           
$mail->Host = "localhost";  
$mail->SMTPAuth = false;         
$mail->Username = "[email protected]";      
$mail->Password = "xxxxxxx";        
$mail->SMTPSecure = "tls";        
$mail->Port = 25;          
$mail->From = "[email protected]"  
$mail->FromName = "xxx";  
$mail->addAddress("[email protected]", "example");  
$mail->isHTML(true); 
$mail->Subject = "Test"; 
$mail->Body = "<i>Helo</i>"; 
$mail->AltBody = "This is the plain text version of the email content"; 

if(!$mail->send()) 
{ 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} 
else 
{ 
    echo "Message has been sent successfully"; 
} 

?> 

梅勒錯誤:問題,它提供了錯誤代碼SMTP:550

​​
+0

此行是正確的:$ MAIL-> SMTPAUTH = FALSE;?不應該是真的嗎? –

+0

if $ mail - > SMTPAuth = true;同樣,它也會引發同樣的錯誤。 –

+0

你可以嘗試設置'SMTPDebug = 2',這樣你就可以看到實際發生了什麼。 – Synchro

回答

0

有一個偉大的疑難解答用於PHP郵件問題的回答一個相關的問題,PHP mail function doesn't complete sending of e-mail

其中的細節是頭的一些細節,這可能有所幫助。這裏有幾個:

Make sure all mail headers are supplied

Some spam software will reject mail if it is missing common headers such as "From" and "Reply-to":

$headers = array("From: [email protected]", 
    "Reply-To: [email protected]", 
    "X-Mailer: PHP/" . PHP_VERSION 
); 
$headers = implode("\r\n", $headers); 
mail($to, $subject, $message, $headers); 

Make sure mail headers have no syntax errors

Invalid headers are just as bad as having no headers. One incorrect character could be all it takes to derail your email. Double-check to make sure your syntax is correct as PHP will not catch these errors for you.

$headers = array("From [email protected]", // missing colon 
    "Reply To: [email protected]",  // missing hyphen 
    "X-Mailer: "PHP"/" . PHP_VERSION  // bad quotes 
);