Page 1 of 1

php contact form question

Posted: Mon Oct 16, 2006 1:26 pm
by mikewooten
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

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> 

Here is my form

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> 
Here is my contact.php page code

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.";
} 
?>

Posted: Tue Oct 17, 2006 2:28 am
by thomas777neo
I don't think you can automatically send an email back. But you should be able to add something to the header of the email to attach a receipt. So that if the person opens the email and the email client understands the receipt concept, it should ask if a mail should be sent back.

Just an idea, otherwise I think it would be more of a virus than anything else.

Posted: Tue Oct 17, 2006 11:50 am
by mikewooten
how can i get this to work without it being a virus?

Posted: Tue Oct 17, 2006 11:56 am
by Chris Corbyn
What are you trying to do? Send a copy to the recipient and a copy to yourself? Or do you want to be notified once the recipient has opened the email?

The latter is an invasion of privacy unless the recipient explicitly asks for you to know; in which case ask them to reply keeping the subject line in-tact or something.

Posted: Tue Oct 17, 2006 12:15 pm
by mikewooten
the form works as far as sending an email, but i would like for that person who is sending that email through the form to get an email back to them saying "Your email was sent successfully to person. We will respond as soon as possible." in the email and "Thanks for your email inquiry" in the header. When i try to use the form, the form does send the email, but, i get no email back to me saying that, the email does not show up. i would like it to show up.

Posted: Tue Oct 17, 2006 1:49 pm
by RobertGonzalez
Two emails: one to the recipient and one to the sender.

Posted: Tue Oct 17, 2006 2:59 pm
by mikewooten
yes, i would like Two emails: one to the recipient and one to the sender.
i have the code set up as in my first message at top, but the email that is supposed to go to the recipient does not go to the recipient, it just doesn't show up for some reason, i would like that email to show up in their email.
how can i get this to work? what do i need to change or add to my code to get this to work?
thanks

Posted: Tue Oct 17, 2006 3:16 pm
by Chris Corbyn
Have you echoed out the contents of the variables you're passing to mail() ?

Also, mail sent via mail() in such a loose fashion is often blocked by spam checkers. It may be the case that the mail is sending but it's being blocked.

Posted: Tue Oct 17, 2006 5:43 pm
by mikewooten
i have echoed out mail. this is what i did:

Code: Select all

print_r($_POST);
and the result on contact.php is:

Code: Select all

Array ( [name] => test6 [user_email2] => masq920@yahoo.com [message] => test6 [submit] => Submit )
i have also tried

Code: Select all

if($autorespond == TRUE)
{
echo "TRUE";
}
else
{
echo "FALSE";
}
and the result came back TRUE

also, your saying that mail() is being blocked by spam checkers and the email might be getting blocked?
well, how can i get around that and make sure that the email gets through without it being blocked by spam checkers?
what code can i use to get around that?
thanks

Posted: Tue Oct 17, 2006 5:49 pm
by Chris Corbyn
It's only a possibility that it's being blocked; I can't really say without monitoring what goes through the server.

Either way to lessen the chance of being blocked you have two options:

1. Study how to build correctly formatted emails
2. Download a library designed to do the above (PHPMailer or Swift Mailer)

Posted: Tue Oct 17, 2006 6:20 pm
by mikewooten
where can i find a library of PHPMailer or Swift Mailer and
what are some good php site on how to build correctly formatted emails?
thanks

Posted: Tue Oct 17, 2006 6:40 pm
by Chris Corbyn
mikewooten wrote:where can i find a library of PHPMailer or Swift Mailer and
what are some good php site on how to build correctly formatted emails?
thanks
Is Google broken?