php contact form question
Posted: Mon Oct 16, 2006 1:26 pm
I have a contact form here: http://www.wootenmedia.com/contact_test/contact.html
when you enter your information, it does send an email to the sender, but it does not send an email back to the sender.
for example, when you enter your email address in the email field, i do not get an email back saying that i have sent the email, i would like to have the email field send back an email to the sender saying that i have sent an email.
can you take a look at my code and let meknow what do i need to add to my code or change in my code in order to do that?
here is my code that i am using below.
thanks
Code for contact.html
Here is my JavaScript Code
Here is my form
Here is my contact.php page code
when you enter your information, it does send an email to the sender, but it does not send an email back to the sender.
for example, when you enter your email address in the email field, i do not get an email back saying that i have sent the email, i would like to have the email field send back an email to the sender saying that i have sent an email.
can you take a look at my code and let meknow what do i need to add to my code or change in my code in order to do that?
here is my code that i am using below.
thanks
Code for contact.html
Here is my JavaScript Code
Code: Select all
<SCRIPT language="JavaScript" type="text/javascript">
function thevalidEmail(email) {
invalidChars = " /:,;"
if (email == "") {
return false
}
for (i=0; i<invalidChars.length; i++) {
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar,0) > -1) {
return false
}
}
atPos = email.indexOf("@",1)
if (atPos == -1) {
return false
}
if (email.indexOf("@",atPos+1) != -1) {
return false
}
periodPos = email.indexOf(".",atPos)
if (periodPos == -1) {
return false
}
if (periodPos+3 > email.length) {
return false
}
return true
}
function validName(name) {
if (name == "") {
return false
}
}
function validMessage(message) {
if (message == "") {
return false
}
}
function isNum(passedVal) { // Is this a number?
if (passedVal == "") {
return false
}
for (i=0; i<passedVal.length; i++) {
if (passedVal.charAt(i) < "0") {
return false
}
if (passedVal.charAt(i) > "9") {
return false
}
}
return true
}
function submitIt2(carForm2) {
// check to see if the email's valid
if (!thevalidEmail(carForm2.user_email2.value)) {
alert("Invalid email address")
carForm2.user_email2.focus()
carForm2.user_email2.select()
return false
}
if (carForm2.name.value == "") {
alert("Must Enter NAME")
carForm2.name.focus()
carForm2.name.select()
return false
}
if (carForm2.message.value == "") {
alert("Must Enter MESSAGE")
carForm2.message.focus()
carForm2.message.select()
return false
}
}
</SCRIPT>
Code: Select all
<form action="contact.php" method="post" onsubmit="return submitIt2(this)" name="myForm2">
<p><font color="#ff0000">*</font>Name:<br>
<input type="text" name="name" size="35" id="name">
</p>
<p><font color="#ff0000">*</font>Email:<br>
<input name="user_email2" type="text" size="35" id="user_email">
</p>
<p><font color="#ff0000">*</font>Message:<br>
<textarea name="message" rows="10" cols="27" id="message"></textarea>
</p>
<p>
<input type="submit" name="submit2" value="Submit">
</p>
</form>
Code: Select all
<?php
#catch and store the content from the form
$name = $_POST["name"];
$user_email2 = $_POST["user_email2"];
$message = $_POST["message"];
#some variables storing info about you
$auth_name2 = "Mike Wooten";
$auth_email2 = "mikewooten@wootenmedia.com";
$auth_site2 = "Mike Wooten Stoddard site";
#Auto-Resopnd to person sending mail indicating success
$autorespond = mail("$user_email2", "Thanks For Your Email Inquiry", "Your email was sent successfully to $auth_name2. We will respond as soon as possible.","From:$auth_email2\r\nReply-to:$auth_email2");
#Send the email to the author
if(mail("$auth_email2", "Email From $auth_site2", "From: $name
Email: $user_email2
Message: $message","From:$user_email2\r\nReply-to:$user_email2")){
echo "Thank You <b>$name</b> for contacting <b>$auth_name2</b>, I will respond as soon as possible. <br>Your message has been successfully sent!";
}else{
echo "There was a problem sending your message. We applogize for the inconvenience.";
}
?>