Jump to content


Photo

how can I test php mail?


  • Please log in to reply
4 replies to this topic

#1 wright67uk

wright67uk

    Advanced Member

  • Members
  • PipPipPip
  • 438 posts

Posted 05 May 2013 - 04:51 PM

What is the best way to test an email has been sent when using php mail?

 

I need to add a mysql update, but I need to test that the email has definitely been sent.

 

Is it good enough to put the below code into an IF block?



 $to      = $user_email;
 $subject = 'A reminder from TNT';
 $message = $info_msg;
 $headers = 'From: reminder@reminder.com' . "\r\n" .
    'Reply-To: reminder@reminder.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

// if mail sent then do this...


#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 05 May 2013 - 05:06 PM

mail() returns a boolean. However, it does only ensure it was sent, not recieved.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 wright67uk

wright67uk

    Advanced Member

  • Members
  • PipPipPip
  • 438 posts

Posted 05 May 2013 - 05:18 PM

Thankyou

 

so... 

if (mail($to, $subject, $message, $headers))
{do this};

and how in-depth would it be to test for returned messages ie. undeliverable? 



#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 05 May 2013 - 05:28 PM

Very.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 wright67uk

wright67uk

    Advanced Member

  • Members
  • PipPipPip
  • 438 posts

Posted 05 May 2013 - 05:36 PM

Ok lol thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com