2012-09-24 70 views
0

嗨我正在使用phpMailer發送電子郵件。它在服務器上工作正常,但是當我試圖從本地機器(本地主機)發送郵件時,它給我錯誤。我使用Gmail SMTPPHP郵件程序SMTP錯誤

<? 
require("lib/class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPAuth = true; 
$mail->Mailer = "smtp"; 
$mail->Host = "ssl://smtp.gmail.com"; 
$mail->Port = 465; 
$mail->Username = "[email protected]"; // SMTP username 
$mail->Password = "XXXXXXX"; // SMTP password 
$mail->From = $email; 
$mail->AddAddress("[email protected]", "XX XX XX"); 
$mail->WordWrap = 50; 
$mail->IsHTML(true); 
$mail->Subject = "You have received feedback from your website!"; 
$mail->Body = $message; 
$mail->AltBody = $message; 
if(!$mail->Send()) 
{ 
    echo "Message could not be sent. <p>"; 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    exit; 
} 

} 
?> 

,誤差

SMTP Error: Could not connect to SMTP host. Message could not be sent. 

Mailer Error: SMTP Error: Could not connect to SMTP host. 

它在我的服務器工作正常。

+0

那你的互聯網連接的代碼,你使用防火牆或一些東西可以嘗試禁用它 –

+1

我不認爲'SSL: // smtp.gmail.com'是一個主機名。 –

+0

@ aravind.udayashankara我關掉了防火牆...... :-( – Rakesh

回答

1

好吧我明白了在本地這裏是我用

<?php 
    require("phpmailer/class.phpmailer.php"); 
    $mail = new PHPMailer(); 
    $mail->IsSMTP(); // send via SMTP 
    IsSMTP(); // send via SMTP 
    $mail->SMTPAuth = true; // turn on SMTP authentication 
    $mail->Username = "[email protected]"; // SMTP username 
    $mail->Password = "password"; // SMTP password 
    $webmaster_email = "[email protected]"; //Reply to this email ID 
    $email="[email protected]"; // Recipients email ID 
    $name="name"; // Recipient's name 
    $mail->From = $webmaster_email; 
    $mail->FromName = "Webmaster"; 
    $mail->AddAddress($email,$name); 
    $mail->AddReplyTo($webmaster_email,"Webmaster"); 
    $mail->WordWrap = 50; // set word wrap 
    $mail->IsHTML(true); // send as HTML 
    $mail->Subject = "This is the subject"; 
    $mail->Body = "This is the HTML BODY "; //HTML Body 
    $mail->AltBody = "This is the body when user views in plain text format"; //Text Body 
    if(!$mail->Send()) 
    { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
    } 
    else 
    { 
    echo "Message has been sent"; 
    } 
    ?> 
+0

其他代碼是否相同?? – Rakesh

+0

嘿,等待我正在粘貼實際代碼1分我想我明白了你的問題 –

+0

好吧我會在這裏... – Rakesh