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 = "dennismonsewicz@gmail.com";
$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
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
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.