【发布时间】:2017-11-26 14:57:26
【问题描述】:
我正在尝试从本地主机发送邮件。我使用的是 xampp,但每次我都收到相同的错误提示“未找到主机”,请帮忙。
这是我的 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 = bajajsb08@gmail.com
; 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
auth_username=bajajsb08@gmail.com
auth_password=******
force_sender=bajajsb@gmail.com
hostname=smtp.gmail.com
这里是调试日志
17/06/23 11:25:06 ** --- MESSAGE BEGIN ---
17/06/23 11:25:06 ** To: bajajsb08@gmail.com
17/06/23 11:25:06 ** Subject: Test email
17/06/23 11:25:06 ** From: bajajsb@gmail.com
17/06/23 11:25:06 ** Reply-To: bajajsb@gmail.com
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 = 'bajajsb08@gmail.com';
$subject = 'Test email';
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: bajajsb@gmail.com\r\nReply-To: bajajsb@gmail.com";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
【问题讨论】:
-
如果您的防火墙可以阻止 apache 的互联网连接。确定
-
在那里检查没问题。
-
请有人帮助我,我的项目因此而停止:(