Jump to content

mail() returns false but email is sent


SonyaS

Recommended Posts

Hi, I'm pretty new to PHP and I am working on a form that sends and email. I want to display a message if the mail can't be sent (i.e. if mail() returns false) and a different message if mail() returns true, except it is returning false even though the emails are sending.

 

 

Basically I have used:

 

$to = 'myemail@email.com';

$subject = "Subject Line Goes here";

$headers = "From: $email";

$message = 'My message';

 

$mailSent = mail($to, $subject, $message, $headers);

 

In testing it I have used the following to determine what is going on:

 

if (isset($mailSent)) { echo '$mailSent ='.$mailSent; } - echo's nothing

if ($mailSent == FALSE) { echo '$mailSent = FALSE'; } - echo's '$mailSent = FALSE'

if ($mailSent == TRUE) { echo '$mailSent = TRUE'; } - echo's nothing

if (is_null($mailSent)) { echo '$mailSent = NULL'; } - echo's '$mailSent = NULL'

echo '$mailSent ='.$mailSent; - echo's '$mailSent ='

 

Any help would be greatly appreciated!

Thanks!

Link to comment
Share on other sites

Hi Pikachu2000,

 

Thanks for your help.

 

I should have said that previously I had the 'if ($mailSent) { echo 'Mail Sent'; } else { echo 'Mail not sent'; }' statement and this was returning back with the else response when the mail was actually sent.

 

The var_dum($mailSent) returns NULL.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.