Jump to content

Contact Form - Fails Everytime. Bad Code?


Recommended Posts

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 = 'blah@blah.com';
$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 blah@blah.com');
	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

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?

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.