2011-01-22 52 views
1

我已經寫了一小塊的PHP代碼發送郵件:無法連接到郵件服務器在PHP

<?php 
    //define the receiver of the email 
    $to = '[email protected]'; 
    //define the subject of the email 
    $subject = 'Hishob email'; 
    //define the message to be sent. Each line should be separated with \n 
    $message = "Hello World!\n\nThis is my first mail."; 
    //define the headers we want passed. Note that they are separated with \r\n 
    $headers = "From: [email protected]\r\nReply-To: [email protected]"; 
    //send the email 
    $mail_sent = mail($to, $subject, $message, $headers); 
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed"; 
    ?> 

執行它後,我得到了以下警告:

無法連接到郵件服務器在「localhost」端口25上,在php.ini中驗證您的「SMTP」和「smtp_port」設置或在第11行的C:\ wamp \ www \ NewHishob \ PhpFiles \ send_mail.php中使用ini_set()
郵件失敗

我正在使用WAMP服務器,並且有兩個文件,INI-DIST和其他INI-RECOMENDED。哪一個很重要?

我也通過的php.ini-dist的文件不見了,用於SMTP它包含以下內容:

[mail function] 
; For Win32 only. 
SMTP = localhost 
smtp_port = 25 

; For Win32 only. 
;sendmail_from = [email protected] 

; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 
;sendmail_path = 

請建議我應該怎麼辦呢?感謝所有提前。

+1

WAMP不是服務器。 WAMP是Windows,Apache2 webserver,MySQL dbms和PHP腳本引擎組合的「代號」。 – 2011-01-22 15:19:14

回答

5

您是否該主機/端口組合上的SMTP服務器?你可以看一看是做聽力有:

$ telnet localhost 25 

,看是否telnet實際連接。

0

此外,您不能保證郵件已發送,因爲腳本不會等待郵件服務器繼續。

0

忘掉這個,如果你在本地主機和Windows機器上,就不會工作。
改爲使用PHPMailer
我已經設法通過GMail服務發送電子郵件(僅用於測試)。這真是簡單...試試吧 PHPMailer