Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/96300-solved-email-script-not-working/
Share on other sites

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>

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.