Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Email Form 1

Status
Not open for further replies.

Newb2IT

IS-IT--Management
Oct 6, 2008
205
US
Hi guys I have an easy form on my site where a user enters some information and then when he clicks on the submit button i want to get an automatic email that tells me that the users submitted a form...i do get the email but the email body has only this info:

"just filled in your comments form. They said:

Their e-mail address was:"

The name variable and email address variable ar enot being sent, not sure why. attached is a copy of the code...anything wrong?...also are there any email forms already on the internet that i can use its code for testing?... Thanks guys
 
Basically your code is running when the page loads, and then never again, because your form immediately redirects to thankyou.php when its submitted.

When the page loads nothing has been put into the form, so the variables are blank. The email gets sent upon loading of the page with no information. Then your page proceeds to show the form to be filled in and submitted.

Basically what you would want to do, is have the form either submit to itself so the code can be run with the values, or have your email code in your thankyou page instead.

You are jumping the gun so to speak.

Tip: you can post straight code here, just make sure you post it between code tags. [ignore]
Code:
[/ignore]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks! That fixed my issue!...by the way are there any php email form codes that i could use that are already made and available?
 
by the way....it would be awesome if i could also add code that will also send an email to the person that submitted the form to let him know that we have received his request....is this possible? if so what code should i add?
 
I guess there should be. Googling for it offered quite a few hits.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Just add a second email line.

Code:
if(mail([red]$email[/red],"Comments Received",$message2,"From:mail@website.com")){
echo "Confirmation email sent to your email $name";
}
else{
echo "Confirmation email could not be sent to your email $name , make sure your email $email is correct.";
}

Where [red]$email[/red] is the email from the person that fille din the form.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
the mail@website.com should be replaced with my email address correct?
 
Correct.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
And $message2 should be replaced with whatever you want the email message to say to the user. whether you want to include their submitted information or not.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita i tried it and i got no errors but the person submitting the request did not get a conformation email..im not sure why...this is the code I have:

Code:
<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}

$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$comments=$_POST['comments'];
checkOK($comments);
$to="admin@cvdequipment.com";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
if(mail($email,"Comments Received",$message2,"From:mail@website.com")){
echo "Confirmation email sent to your email $name";
}
else{
echo "Confirmation email could not be sent to your email $name , make sure your email $email is correct.";
}
}
?>
 
i did add $message2="$name Thanks"; below $message
 
so basically this is what I have but still not working :-(
Code:
<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}

$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$comments=$_POST['comments'];
checkOK($comments);
$to="admin@cvdequipment.com";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
$message2="$name Thanks";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
if(mail($email,"Comments Received",$message2,"From:admin@cvdequipment.com")){
echo "Confirmation email sent to your email $name";
}
else{
echo "Confirmation email could not be sent to your email $name , make sure your email $email is correct.";
}
}
?>
 
Thanks Vacunita I got it working thanks to your help!
 
Sorry, I couldn't get back to this sooner, But glad you managed to fix it.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top