dennismonsewicz Posted September 17, 2008 Share Posted September 17, 2008 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? Quote Link to comment Share on other sites More sharing options...
uniflare Posted September 17, 2008 Share Posted September 17, 2008 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.