2011-06-11 53 views
2

我使用phpmailer類發送電子郵件。我的geeting錯誤「無法執行:/ smtp」下面的代碼是下面的代碼。有人可以建議我有什麼問題。使用phpmailer類

require '../class.phpmailer.php'; 

try { 
    $mail = new PHPMailer(true); //New instance, with exceptions enabled 

    $body    = file_get_contents('contents.html'); 
    echo $body; 
    $body    = preg_replace('/\\\\/','', $body); //Strip backslashes 

    $mail->IsSMTP();       // tell the class to use SMTP 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->Port  = 25;     // set the SMTP server port 
    $mail->Host  = "ssl://smtp.gmail.com"; // SMTP server 
    $mail->Username = "[email protected]";  // SMTP server username 
    $mail->Password = "1234567889";   // SMTP server password 

    $mail->IsSendmail(); // tell the class to use Sendmail 

    $mail->AddReplyTo("[email protected]","First Last"); 

    $mail->From  = "[email protected]"; 
    $mail->FromName = "First Last"; 

    $to = "[email protected]"; 

    $mail->AddAddress($to); 

    $mail->Subject = "First PHPMailer Message"; 

    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
    $mail->WordWrap = 80; // set word wrap 

    $mail->MsgHTML($body); 

    $mail->IsHTML(true); // send as HTML 

    $mail->Send(); 
    echo 'Message has been sent.'; 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); 
} 
+0

你得到什麼錯誤究竟在行? – 2011-06-11 09:00:43

回答

4

通過使用GMail,您的設置可能不正確;請嘗試以下(更正端口和SSL地址):

$mail->Port  = 465;     // set the SMTP server port 
$mail->Host  = "ssl://smtp.gmail.com"; // SMTP server 
$mail->Username = "[email protected]";  // SMTP server username 
$mail->Password = "1234567889"; 

或者,使用TLS:

$mail->Port  = 587;     // set the SMTP server port 
$mail->Host  = "tls://smtp.gmail.com"; // SMTP server 

編輯:刪除下面(你先提供設置使用SMTP這條線,然後你告訴它使用和發送低谷sendmail和你在configs中放錯了路徑。只需堅持一個服務,使用SMTP以上設置(或編輯2下面),看看):

刪除:

$mail->IsSendmail(); // tell the class to use Sendmail 

EDIT2:其他選項(如果第一個答案不工作):

$mail->SMTPSecure = 'ssl'; 
$mail->Host = 'smtp.gmail.com'; 
+0

我改變了代碼,但問題依然存在。不能執行:/ smtp – Deepa 2011-06-11 09:04:05

+0

@Deepa你應該給我們更多的信息,然後清楚地說明你收到的錯誤信息。如果(!stristr(ini_get('sendmail_path'),'sendmail')){$ this-> Sendmail ='/ var/qmail/bin/sendmail',則在公共函數IsSendmail(){ – 2011-06-11 09:04:48

+0

; } $ this-> Mailer ='sendmail'; } 我剛剛將sendmail路徑更改爲'/ smtp'。 – Deepa 2011-06-11 09:06:47