perplexeddev Posted April 18, 2014 Share Posted April 18, 2014 I am new to PHP, I have a website done in HTML and PHP.In my site,I have a form that sends mail. My PHP code is ?php try{ $to = 'test@test.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: noreply@test.com' . "\r\n" . 'Reply-To: test@test.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if(mail($to, $subject, $message, $headers)) { echo("<p>Email successfully sent!</p>"); } else{ echo("<p> Email delivery failed </p>"); } } catch(Exception $e){ echo 'Caught Exception', $e->getMessage(), "\n"; } ?> I am using valid to and from addresses, but i always get the message "Email delivery Failed" and I dont get the email. Also I have deployed my website in windows server, are there any configurations to be done on the server. Thanks for your help in advance. Quote Link to comment Share on other sites More sharing options...
denno020 Posted April 19, 2014 Share Posted April 19, 2014 (edited) What have you searched for on Google? http://stackoverflow.com/questions/17135829/sending-php-mail-from-windows-server Edited April 19, 2014 by denno020 Quote Link to comment Share on other sites More sharing options...
Ansego Posted April 19, 2014 Share Posted April 19, 2014 Hi, @ DENNO020 : Feel honoured, he came here for help. Divide and conquer... Code looks fine, though I am tired and had a few to many drinks, lets assume all is ok, since no other errors came up... Give this a try: Check if your SMTP is setup (Reference: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-ba78-3f287a2b88f2.mspx?mfr=true), Check Port 25 is open on the server, Check your php.ini is setup to these configurations: http://www.php.net/manual/en/mail.configuration.php. Note: If you are using a home computer for the server, beware that some ISP's block port 25, alternative ports can be used default ports: 25 or 587 (reference: http://www.arclab.com/en/amlc/list-of-smtp-and-pop3-servers-mailserver-list.html) See how you go, if none of above helps, please let us know, we are always happy to help. Quote Link to comment Share on other sites More sharing options...
perplexeddev Posted April 22, 2014 Author Share Posted April 22, 2014 I tried all the steps mentioned above but I still get the message "Email delivery Failed".I saw the following error in PHP Log: PHP Warning : mail(): SMTP server response: 530 5.7.1 Client was not authenticated in on line 10. Line 10 is if(mail($to, $subject, $message, $headers)) in my PHP file. Quote Link to comment Share on other sites More sharing options...
IanA Posted April 23, 2014 Share Posted April 23, 2014 Is SMTP authenticated through IIS currently? If so, I would recommend looking into one of the mailer libraries available for PHP, they are far more flexible than the original mail library and support sending through authenticated servers. 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.