mrusho Posted September 28, 2011 Share Posted September 28, 2011 Hello, I have a contact form that is not working. It just keeps providing the failed delivery message specified in the contact. php file. Any help would be much appreciated. Thanks, <?php $field_department = $_POST['cf_department']; $field_message = $_POST['cf_message']; $mail_to = '[email protected]'; $subject = 'Website Feedback'; $body_message .= 'Addressed to: '.$field_department."\n"; $body_message .= 'Message: '.$field_message; $mail_status = mail($mail_to, $subject, $body_message); if ($mail_status) { ?> <script language="javascript" type="text/javascript"> alert('Thank you for your feedback.'); window.location = 'contact.html'; </script> <?php } else { ?> <script language="javascript" type="text/javascript"> alert('Message failed. Please, send an email to [email protected]'); window.location = 'contact.html'; </script> <?php } ?> ------------------------------------------------ <form action="contact.php" method="post"> <ol><li> </li><li> <label for="department">Addressed to:</label> <input type="text" name="cf_department" class="text" /> </li><li> <label for="message">Your Message:</label> <textarea name="cf_message"rows="10" cols="50"></textarea> </li><li> <input type="submit" value="send" /><input type="reset" value="Clear"/> <div class="clr"></div> </li></ol> </form> Link to comment https://forums.phpfreaks.com/topic/248041-contact-form-fails-everytime-bad-code/ Share on other sites More sharing options...
gristoi Posted September 28, 2011 Share Posted September 28, 2011 echo out $mail_status to see if it is returning true or not. do you have a mail server set up to test this on? if you are just trying it from your pc as a localhost then it will always fail Link to comment https://forums.phpfreaks.com/topic/248041-contact-form-fails-everytime-bad-code/#findComment-1273591 Share on other sites More sharing options...
mrusho Posted September 28, 2011 Author Share Posted September 28, 2011 echo out $mail_status to see if it is returning true or not. do you have a mail server set up to test this on? if you are just trying it from your pc as a localhost then it will always fail Thanks for the reply, This is located on my companies local web server hosted using IIS. We have an email server setup (everything was setup before I got here) but I'm not even sure where to check to see if it is connected to the mail server. Any ideas? Link to comment https://forums.phpfreaks.com/topic/248041-contact-form-fails-everytime-bad-code/#findComment-1273594 Share on other sites More sharing options...
the182guy Posted September 28, 2011 Share Posted September 28, 2011 Check the SMTP settings in your php.ini config file. Link to comment https://forums.phpfreaks.com/topic/248041-contact-form-fails-everytime-bad-code/#findComment-1273608 Share on other sites More sharing options...
PFMaBiSmAd Posted September 28, 2011 Share Posted September 28, 2011 See if there are any php errors being reported. Add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(-1); Link to comment https://forums.phpfreaks.com/topic/248041-contact-form-fails-everytime-bad-code/#findComment-1273610 Share on other sites More sharing options...
Maq Posted September 28, 2011 Share Posted September 28, 2011 mrusho, in the future, please place OR tags around your code. Link to comment https://forums.phpfreaks.com/topic/248041-contact-form-fails-everytime-bad-code/#findComment-1273611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.