0

i am using the following code to sendmail using php mail() function.but it does not work.

$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>");
}

when i check in mail.log file the error is like following:

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;

can anyone know why return path is set to "www-data@localhost.localdomain"?

how can i change it? the problem that i am facing is for yahoo and hotmail account as not receiving emails.

i have configured my php.ini like this to send mail:

  [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
user1530848
  • 57
  • 2
  • 8
  • most likely your local server is not setup as a SMTP relay/server. Thus the system will try to send it out using defaults. Either configure your local machine/server with SMTP, or use an external providers such as mailgun or mandril. (I'd go for external provider) – Andrew Killen Nov 21 '16 at 07:20
  • while settng return path i am getting this error while sending mail in yahoo account :** "Connections will not be accepted from 'ip address', because the ip is in Spamhaus's list" ** can you please help how can i fix it? – user1530848 Nov 21 '16 at 07:56
  • 1
    www-data is a user on the system. If you check with `ls -l` inside your folder, you should see that owner of www/ folder is www-data. This is a user that comes with Apache which has restricted right. For your problem, you should check your configuration in you php.ini. Have you configure sendmail ? If not, your server does not know how to send your mail. – Anthony Nov 21 '16 at 08:44

0 Answers0