0

I have an email form that isn't working. I even copied and pasted exact syntax and inserted my email address. My error handling says its working but I am not receiving the email. and yes I have checked my spam. Here is my code:

$to      = 'krummens@krummens.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: krummens@yahoo.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$mailResult = mail($to, $subject, $message, $headers);
if($mailResult) {
echo "Email sent to " . $to;
}
else {
echo "Error sending email";
}

and the result on the page is:

Email sent to krummens@yahoo.com

Any help?

krummens
  • 837
  • 2
  • 17
  • 38
  • Check if SMTP is installed and turned on by running phpinfo(); –  Jan 13 '15 at 16:16
  • 1
    Just because `mail()` returns true, doesn't mean the mail was actually sent. It just means it was passed off to the system's mail handler. "Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise. It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination." – j08691 Jan 13 '15 at 16:17
  • Also check the output of your mail log, apache log and php log (if present) – Curtis Mattoon Jan 13 '15 at 16:17
  • I suggest you to use http://swiftmailer.org/docs/introduction.html because the mail function can be problematic in many cases. Google about it. – Whirlwind Jan 13 '15 at 16:21
  • @KoenHoeijmakers: my phpinfo() says "localhost". Is this what it is supposed to be? – krummens Jan 13 '15 at 16:28

1 Answers1

-1

You need to turn on mail in your php.ini. Just because the function returns true doesn't mean the mail was actually sent.

Like this:

In php.ini:

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i -f  me@example.com

From the docs:

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

Rupert
  • 1,629
  • 11
  • 23