2010-01-02 75 views
12

發送電子郵件,我用的是最新的WAMP和我得到這個當我嘗試發送電子郵件:與WAMP

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\main\createaccount.php on line 8 

郵件傳遞失敗...

消息:

$to = "[email protected]"; 
$subject = "Hi!"; 
$body = "Hi,\n\nHow are you?"; 
if (mail($to, $subject, $body)) { 
    echo("<p>Message successfully sent!</p>"); 
} else { 
    echo("<p>Message delivery failed...</p>"); 
} 

你還需要下載一個「郵件服務器」嗎?

請幫忙。

回答

1

你沒有在你的機器上運行一個smtp服務器,但你不需要。只需設置SMTP到一個開放的SMTP服務器,例如:

ini_set('SMTP', 'smtp.yourisp.com'); 

看看你的ISP的主頁或http://www.e-eeasy.com/SMTPServerList.aspx的SMTP服務器列表。

如果您有桌面郵件程序,則可以使用與用於發送郵件相同的地址。

+0

thanksman,嘗試了許多服務器沒有,但我得到了同樣的錯誤消息,也許是其他一些程序我運行使用25端口;/ – Jorm 2010-01-02 22:34:44

+0

確定你是把'ini_set'的'mail'功能前,有你嘗試過你自己的ISP的SMTP服務器? – 2010-01-02 22:38:06

0

我認爲你的郵件服務器(SMTP)發送郵件服務器沒有在你的php.ini文件中配置。

看一看這樣的:

http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Remote_SMTP_Server_for_Sending_Mail.htm

而且Hotmail不使您可以使用自己的郵件服務器。你應該使用雅虎或Gmail。

+1

至少Gmail需要SSL保護連接,所以這不適用於普通的舊郵件()。 – 2010-01-02 22:29:40

+0

@Tatu Ulmanen:謝謝:)我不認爲雅虎是這樣做的,我記得。 – 2010-01-02 22:41:20

0

你確定這些服務器上安裝了郵件程序嗎?如果沒有,那是你的問題。例如,XAMPP附帶一個名爲Mercury的郵件程序,您必須先啓動它才能通過服務器發送郵件。

14

這適用於我,應該爲你工作:使用Fake Sendmail和虛擬主機郵件服務器(即 - Godaddy,1and1等)。

1.)下載sendmail壓縮包並將其解壓縮到C:\ Wamp \ bin \ sendmail(就此示例而言)。

2)編輯C:\ WAMP \ BIN \ sendmail的\ sendmail.ini並設置以下到您的郵件服務器的要求(我的是下圖):

smtp_server=mail.yourdomain.com 
smtp_port=26 
smtp_ssl=none 
;default_domain=yourdomain.com 
[email protected] 
auth_password=smtppassword 
;pop3_server= 
;pop3_username= 
;pop3_password= 
;force_sender= 
;force_recipient= 

3)設置sendmail的路徑.exe在您的php.ini文件中。

[mail function] 
; For Win32 only. 
SMTP = 

; For Win32 only. 
sendmail_from = 

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

4.)重新啓動Wampserver。

使用Gmail可能會取得成功,但還有一些額外的調整可以使其發揮作用。我更喜歡使用我上傳代碼的虛擬主機的郵件服務器。

+0

正是我需要鏈接我的開發。環境與實際的GoDaddy帳戶。非常感激 ! – 2010-03-25 18:00:03

+0

+1拉起一條2歲的線,但這只是救了我。 – msanford 2012-03-15 18:17:27

+0

這工作!謝謝。這救了我。所有突然的Wamp64服務器停止在本地主機的開發工作,這救了我。 – GunWanderer 2017-05-28 08:59:39

0

請按照這篇文章,它適用,如果你有一個Gmail帳戶。 或至少任何你知道服務器,端口和這個東西的電子郵件帳戶。

Send Email From localhost

0

這裏是另一種解決方案 - WAMP send Mail using SMTP localhost


記住,每次,更改後的php.ini,

必須重新啓動WAMP

(!!!)

ps在php.ini中,我已經使用:

SMTP = localhost 
smtp_port = 25 
sendmail_from = [email protected] 

,或者如果奧尤着編輯的php.ini,試圖插入你的PHP腳本,這些行。

ini_set("SMTP", "localhost"); 
ini_set("smtp_port", "25"); 
ini_set("sendmail_from", "[email protected]"); 
+0

這不起作用。 – Draken 2015-07-04 17:27:26