Jump to content

mail function


dennismonsewicz

Recommended Posts

I am trying to send an email on my server using PHP and i keep getting the error message if the mail fails

 

Here is my code:

 

<?PHP
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

 

Is there any place to check to see if mail is running?

Link to comment
https://forums.phpfreaks.com/topic/124639-mail-function/
Share on other sites

Ok, i assume your running your own Windows Webserver like apache or similar.

 

So you want to check if mail() is available in your current environment, if a very simple email like the one your sending doesn't work make sure you have an SMTP server running on your box.

 

One i have used is QK SMTP free Mail Server, Though its always best to test off an actual webhost to test more advanced emails (html/java etc).

 

Also with my fiddling over the years i've found mail() can be tempremental (it wont send an email but wont return false), in this case you may want to check certain php.ini variables such as safe mode and "Dissallowed Function" Lists etc as the latter will prevent the function from running (Meaning no returned value true or false regardless).

 

Also check the online php manual on mail() functions, it's very useful and gives an alternate solution using PEARs implementation which is Quicker/More Reliable/Probably More Secure, though some hosts may not enable this sort of functionality.

 

 

hope this helps,

Link to comment
https://forums.phpfreaks.com/topic/124639-mail-function/#findComment-643720
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.