0

I recently shifted my servers and found that default PHP mail function is not working which was working in the previous server. I tested it by writing simple mail function

$mailto="me@domain.com";  //Enter recipient email address here

$subject = "Test Email";

$from="you@domain.com";          //Your valid email address here

$message_body = "This is a test email from Webmaster.";

$mail =   mail($mailto,$subject,$message_body,"From:".$from);
var_dump($mail);
if($mail) {
    echo "Your email has been sent successfully";
} else {
    echo "not sent";
}

Above code return me false value. I googled it. checked my PHP.ini. It is also set as the solution mentioned in the google links.

; 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 = "/usr/sbin/sendmail -t -i"

I don't what I am missing.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
user375947
  • 130
  • 12

2 Answers2

1

It returns FALSE, it means there is a problem with your mail configuration. You would need to check the mail log to see if you are getting any errors. The kicker is that php may be handing off the mail, your server may be sending off the mail, and it may get spam filtered along the way.

<?php 
    mail('nobody@example.com', 'the subject', 'the message', null, '-fwebmaster@example.com'); 
?> 
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Harsh Barach
  • 947
  • 9
  • 18
-1

Syntax

bool mail ( string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]] )

Try like this

$mail =   mail($mailto,$subject,$message_body,null,"From:".$from);

Refer this

Jagan
  • 111
  • 2
  • 11