2017-09-15 169 views
0

我一直在嘗試使用xampp上的php郵件發送郵件,並且我確實收到此錯誤,說 無法發送消息。郵件程序錯誤:以下發件人地址失敗:[email protected]:未連接的叫做Mail()如何在xampp上使用phpmailer發送郵件

請幫我解決這個問題。 這是我的代碼;

<?php 
require('class.phpmailer.php'); 

    $mail = new PHPMailer; 
    $mail->IsSMTP(); 
    $mail->SMTPAuth = true; 
    $mail->Host = "tls://smtp.gmail.com"; 
    $mail->Port = 25; 
    $mail->Username = "[email protected]"; 
    $mail->Password = "xxxxx"; 
    //Sending the actual email 
    $mail->setFrom('[email protected]', 'Aaron'); 
    $mail->addAddress('[email protected]', 'Aaron');  // Add a recipient 
    $mail->isHTML(false);         // Set email format to HTML 
    $mail->Subject = 'Calculation form results from '; 
    $mail->Body = 'testing...'; 

    if(!$mail->send()) { 
    echo 'Message could not be sent. '; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
    exit; 
    } 
?> 
+1

複製據PHPMailer的,你應該使用'需要 'PHPMailerAutoload.php' 的教程;'。 另外,它應該是'$ mail = new PHPMailer();'。 https://github.com/PHPMailer/PHPMailer/wiki/Tutorial – IcedAnt

+0

https://support.google.com/mail/answer/7104828?hl=zh-CN&visit_id=1-636410671215867907-2344642736&rd=3 您的端口錯誤。嘗試587 TLS。 – IcedAnt

+0

'$ mail-> Host =「tls://smtp.gmail.com」; $ mail-> Port = 587;'仍然是一樣的錯誤 –

回答

1

從字面上https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

//Create a new PHPMailer instance 
$mail = new PHPMailer; 

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

//Set the hostname of the mail server 
$mail->Host = 'smtp.gmail.com'; 
// use 
// $mail->Host = gethostbyname('smtp.gmail.com'); 
// if your network does not support SMTP over IPv6 

//Set the SMTP port number - 587 for authenticated TLS 
$mail->Port = 587; 

//Set the encryption system to use - ssl (deprecated) or tls 
$mail->SMTPSecure = 'tls'; 

//Whether to use SMTP authentication 
$mail->SMTPAuth = true; 

//Username to use for SMTP authentication - use full email address for gmail 
$mail->Username = "[email protected]"; 

//Password to use for SMTP authentication 
$mail->Password = "yourpassword"; 

//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'First Last'); 

//Set an alternative reply-to address 
$mail->addReplyTo('[email protected]', 'First Last'); 

//Set who the message is to be sent to 
$mail->addAddress('[email protected]', 'John Doe'); 
+0

非常感謝你! –

+0

如果有效,你能接受它作爲正確答案嗎? – IcedAnt

+0

噢,只是... –