2017-06-23 84 views
1

我試圖從本地主機發送一封郵件。我使用xampp,但每當我收到同樣的錯誤說「主機未找到」請幫助。在xampp中配置smtp服務

這裏是我的php.ini文件

; For Win32 only. 
; http://php.net/smtp 
SMTP=smtp.gmail.com 
; http://php.net/smtp-port 
smtp_port=587 
; For Win32 only. 
http://php.net/sendmail-from 
sendmail_from = [email protected] 

; For Unix only. You may supply arguments as well (default: "sendmail - 
t"). 
; http://php.net/sendmail-path 
sendmail_path ="\"L:\xampp\sendmail\sendmail.exe\" -t" 

; Force the addition of the specified parameters to be passed as extra 
parameters 
; to the sendmail binary. These parameters will always replace the value of 
; the 5th parameter to mail(). 
;mail.force_extra_parameters = 

; Add X-PHP-Originating-Script: that will include uid of the script followed 
by the filename 
mail.add_x_header=off 

這裏是我的sendmail.ini

[sendmail] 
smtp_server=smtp.gmail.com 
smtp_port=587 
smtp_ssl=auto 
error_logfile=error.log 
debug_logfile=debug.log 
[email protected] 
auth_password=****** 
[email protected] 
hostname=smtp.gmail.com 

這裏的debug.log

17/06/23 11:25:06 ** --- MESSAGE BEGIN --- 
17/06/23 11:25:06 ** To: [email protected] 
17/06/23 11:25:06 ** Subject: Test email 
17/06/23 11:25:06 ** From: [email protected] 
17/06/23 11:25:06 ** Reply-To: [email protected] 
17/06/23 11:25:06 ** 
17/06/23 11:25:06 ** Hello World! 
17/06/23 11:25:06 ** 
17/06/23 11:25:06 ** This is my first mail. 
17/06/23 11:25:06 ** --- MESSAGE END --- 
17/06/23 11:25:07 ** Connecting to smtp.gmail.com:587 
17/06/23 11:25:07 ** Disconnected. 
17/06/23 11:25:07 ** Disconnected. 
17/06/23 11:25:07 ** Disconnected. 
17/06/23 11:25:07 ** Socket Error # 11001<EOL>Host not found. 

這裏基本的郵件腳本我正在運行:

<?php 
$to = '[email protected]'; 
$subject = 'Test email'; 
$message = "Hello World!\n\nThis is my first mail."; 
$headers = "From: [email protected]\r\nReply-To: [email protected]"; 
$mail_sent = @mail($to, $subject, $message, $headers); 
echo $mail_sent ? "Mail sent" : "Mail failed"; 
?> 
+0

如果您有防火牆,可以阻止Apache的互聯網連接。確保 – kodmanyagha

+0

檢查它沒有問題。 – sampan

+0

有人請幫助我,我的項目是因爲這個暫停:( – sampan

回答