peranha Posted March 15, 2008 Share Posted March 15, 2008 I have this script for my contact form, but it is not working. Not sure why it isnt. <?php if (!isset($_POST['submit'])) { // form not submitted } else { // form submitted // get form input // check to make sure it's all there // escape input values for greater safety $name = empty($_POST['name']) ? die ("<b class=red>Enter Your Name</b>") : strip_tags(htmlspecialchars(str_replace($rtags, "", $_POST['name']))); $email = empty($_POST['email']) ? die ("<b class=red>Enter Your email</b>") : $_POST['email']; $subject = empty($_POST['subject']) ? die ("<b class=red>Enter A Subject</b>") : strip_tags(htmlspecialchars(str_replace($rtags, "", $_POST['subject']))); $message1 = empty($_POST['message']) ? die ("<b class=red>Enter A Message</b>") : strip_tags(htmlspecialchars(str_replace($rtags, "", $_POST['message']))); // send e-mail to ... $to = "webmaster@bscardealers.com"; // Your subject $subject = $subject; // From $header = "from: " . $email; // Your message $message = $message1; // send email $sentmail = mail($to,$subject,$message,$header); } if ($sentmail) { // Reload user to the home.php page header("Location: home.php"); } else { echo "<b class=red>There was an error sending your message.</b>"; } ?> When the code is run, I keep getting There was an error sending your message. I use the same script for the register process, and it works fine. Any one have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/96300-solved-email-script-not-working/ Share on other sites More sharing options...
BlueSkyIS Posted March 15, 2008 Share Posted March 15, 2008 i would add an echo to see if this is ever true: if (!isset($_POST['submit'])) Quote Link to comment https://forums.phpfreaks.com/topic/96300-solved-email-script-not-working/#findComment-492941 Share on other sites More sharing options...
redarrow Posted March 15, 2008 Share Posted March 15, 2008 lookup headers.......... Quote Link to comment https://forums.phpfreaks.com/topic/96300-solved-email-script-not-working/#findComment-492947 Share on other sites More sharing options...
peranha Posted March 15, 2008 Author Share Posted March 15, 2008 I took those lines out, and now it goes forwards to the home page, but it does not send the email. contactsub.php <?php // get form input // check to make sure it's all there // escape input values for greater safety $name = empty($_POST['name']) ? die ("<b class=red>Enter Your Name</b>") : strip_tags(htmlspecialchars(str_replace($rtags, "", $_POST['name']))); $email = empty($_POST['email']) ? die ("<b class=red>Enter Your email</b>") : $_POST['email']; $subject = empty($_POST['subject']) ? die ("<b class=red>Enter A Subject</b>") : strip_tags(htmlspecialchars(str_replace($rtags, "", $_POST['subject']))); $message1 = empty($_POST['message']) ? die ("<b class=red>Enter A Message</b>") : strip_tags(htmlspecialchars(str_replace($rtags, "", $_POST['message']))); // send e-mail to ... $to = "webmaster@bscardealers.com"; // Your subject $subject = $subject; // From $header = "from: " . $email; // Your message $message = $message1; // send email $sentmail = mail($to,$subject,$message,$header); if ($sentmail) { // Reload user to the home.php page header("Location: home.php"); } else { echo "<b class=red>There was an error sending your message.</b>"; } ?> contact.php <form action="contactsub.php" method="post" name="contact" onsubmit="return checkForm(this)"> <table id="editform" align="center"> <tr align="left"> <td colspan="2" id="header">Contact Us</td> </tr> <tr id="subject" align="left"> <td>Name: <input type="text" name="name" size="50" class="form_elements_text"/></td> </tr> <tr id="subject" align="left"> <td>Email: <input type="text" name="email" size="50" class="form_elements_text"/></td> </tr> <tr id="subject" align="left"> <td>Subject: <input type="text" name="subject" size="50" class="form_elements_text"/></td> </tr> <tr align="left"> <td> Message:<br /> <textarea rows="10" cols="50" name="message" class="form_elements_text"></textarea> </td> </tr> <tr align="left"> <td colspan="2" id="post"> <input type="submit" name="Post" value="Send Message" class="button" /> <input type="reset" value="Start over" class="button" onclick="javascript:confirm_reset();"/> </td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/96300-solved-email-script-not-working/#findComment-492953 Share on other sites More sharing options...
peranha Posted March 15, 2008 Author Share Posted March 15, 2008 Got it to work. Changed the header info as told here. lookup headers.......... Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/96300-solved-email-script-not-working/#findComment-492955 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.