我使用以下代码使用php mail()函数发送邮件。但它不起作用。
$msg = "This is demo mail";
// send email
$headers = 'From:no-reply@example.com' . "\r\n" ;
$headers .='Reply-To: '. $to . "\r\n" ;
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
if(mail("me@mail.com","Test",$msg,$headers)) {
echo('<br>'."Email Sent ".'</br>');
}
else
{
echo("<p>Email Message delivery failed...</p>");
}
当我检查mail.log文件时,错误如下:
Return-Path: <www-data@localhost.localdomain>
Received: from localhost.localdomain (localhost [127.0.0.1])
by localhost.localdomain with ESMTP id
for <me@mail.com>; Tue, 21 Nov 2016 12:54:46 GMT
Received: (from www-data@localhost)
by localhost.localdomain (8.14.4/8.14.4/Submit) id id;
任何人都可以知道为什么返回路径设置为&#34; www-data@localhost.localdomain"?
我该怎么改变它?我面临的问题是雅虎和hotmail帐户没有收到电子邮件。
我已将我的php.ini配置为发送邮件:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
; 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(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog