我正在尝试从本地主机发送邮件。我正在使用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
这是debug.log
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";
?>
答案 0 :(得分:0)