PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php //SET HEADERS TO ACCEPT A HTML MAIL
$Name = $_POST['txtName'];
$from_email = $_POST['txtEmail'];
//SET EMAIL VARIABLES
$to = "misty@you.com";
$subject = "Contact Form From Stello Home Services";
$message ="<b>Name:</b> ".$_POST["txtName"]."<p/>";
$message .="<b>Email:</b> ".$_POST["txtEmail"]."<p/>";
$message .="<b>Mailing Address:</b> ".$_POST["txtAddress"]."<p/>";
$message .="<b>City, State, and Zip Code:</b> ".$_POST["txtCity"].", ".$_POST["SelState"]." ".$_POST["txtZip"]."<p/>";
$message .="<b>Phone:</b> ".$_POST["txtPhone"]."<p/>";
$message .="<b>Project Type(s):</b> ".$_POST["txtaProjectType"]."<p/>";
$from = $from_email; //set this to the "from email"
//SET EMAIL HEADERS
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " . $Name . "\r\n";
//YOUR MESSAGE CAN BE EMBEDDED WITH THE FIELDS U RECEIVE FROM FORM SUBMISSION
//SEND EMAIL
$sent = mail($to,$subject,$message,$headers,"-f $from")
?>
How would I go about getting the results for the check boxes? There could be more than one choice. Let me share the html code for the check boxes below.
//assume "kitchen" and "bathroom" have been checked
foreach($_POST['chkbox'] as $value)
{
//$value is the value passed from the checkboxes
echo $value .'<br />'; //this will output "bathroom" and "kitchen" on a new line
}
I have gotten the check boxes figured out. But I need help with displaying the results in the email. I did it without using the $message and it showed the results on the web page. This is not what I wanted. I want it to show up on the email the misty@you.com receives. I tried doing it, but I got the following error message:
Parse error: syntax error, unexpected T_FOREACH in /home/stelloho/public_html/contact.php on line 17
Here's the code (Please look at the bolded parts):
<?php //SET HEADERS TO ACCEPT A HTML MAIL
$Name = $_POST['txtName'];
$from_email = $_POST['txtEmail'];
//SET EMAIL VARIABLES
$to = "misty@you.com";
$subject = "Contact Form From Stello Home Services";
$message ="<b>Name:</b> ".$_POST["txtName"]."<p/>";
$message .="<b>Email:</b> ".$_POST["txtEmail"]."<p/>";
$message .="<b>Mailing Address:</b> ".$_POST["txtAddress"]."<p/>";
$message .="<b>City, State, and Zip Code:</b> ".$_POST["txtCity"].", ".$_POST["SelState"]." ".$_POST["txtZip"]."<p/>";
$message .="<b>Phone:</b> ".$_POST["txtPhone"]."<p/>";
//assume "kitchen" and "bathroom" have been checked
[b]$message .="<b>Project Type(s):</b> "
.foreach($_POST['chkbox'] as $value) - [b](where the error message originates from)[/b]{
//$value is the value passed from the checkboxes
echo $value .'<br />'; //this will output "bathroom" and "kitchen" on a new line
}[/b] $message .="<b>Details About Project:</b> ".$_POST["txtaProjectType"]."<p/>";
$from = $from_email; //set this to the "from email"
//SET EMAIL HEADERS
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " . $Name . "\r\n";
//YOUR MESSAGE CAN BE EMBEDDED WITH THE FIELDS U RECEIVE FROM FORM SUBMISSION
//SEND EMAIL
$sent = mail($to,$subject,$message,$headers,"-f $from")
?>
<?php //SET HEADERS TO ACCEPT A HTML MAIL
$Name = $_POST['txtName'];
$from_email = $_POST['txtEmail'];
//SET EMAIL VARIABLES
$to = "misty@you.com";
$subject = "Contact Form From Stello Home Services";
$message ="<b>Name:</b> ".$_POST["txtName"]."<p/>";
$message .="<b>Email:</b> ".$_POST["txtEmail"]."<p/>";
$message .="<b>Mailing Address:</b> ".$_POST["txtAddress"]."<p/>";
$message .="<b>City, State, and Zip Code:</b> ".$_POST["txtCity"].", ".$_POST["SelState"]." ".$_POST["txtZip"]."<p/>";
$message .="<b>Phone:</b> ".$_POST["txtPhone"]."<p/>";
//assume "kitchen" and "bathroom" have been checked
$message .="<b>Project Type(s):</b> ";
foreach($_POST['chkbox'] as $value)
{
//$value is the value passed from the checkboxes
$message.=$value .'<br />';
}
$message .="<b>Details About Project:</b> ".$_POST["txtaProjectType"]."<p/>";
$from = $from_email; //set this to the "from email"
//SET EMAIL HEADERS
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " . $Name . "\r\n";
//YOUR MESSAGE CAN BE EMBEDDED WITH THE FIELDS U RECEIVE FROM FORM SUBMISSION
//SEND EMAIL
$sent = mail($to,$subject,$message,$headers,"-f $from")
?>
Thank you for your help! There is one more thing I need to do. I would like for contact.php page to have a message telling the user if their message was successfully sent and some information. How do I do that? I tried an if statement before, but it didn't work. I am very new to PHP so I am still learning a lot.
<?php //SET HEADERS TO ACCEPT A HTML MAIL
$Name = $_POST['txtName'];
$from_email = $_POST['txtEmail'];
//SET EMAIL VARIABLES
$to = "misty@you.com";
$subject = "Contact Form From Stello Home Services";
$message ="<b>Name:</b> ".$_POST["txtName"]."<p/>";
$message .="<b>Email:</b> ".$_POST["txtEmail"]."<p/>";
$message .="<b>Mailing Address:</b> ".$_POST["txtAddress"]."<p/>";
$message .="<b>City, State, and Zip Code:</b> ".$_POST["txtCity"].", ".$_POST["SelState"]." ".$_POST["txtZip"]."<p/>";
$message .="<b>Phone:</b> ".$_POST["txtPhone"]."<p/>";
//assume "kitchen" and "bathroom" have been checked
$message .="<b>Project Type(s):</b><br>";
foreach($_POST['chkbox'] as $value)
{
//$value is the value passed from the checkboxes
$message.=$value .'<br/>';
}
$message .="<p><b>Details About Project:</b> ".$_POST["txtaProjectType"]."<p/>";
$from = $from_email; //set this to the "from email"
//SET EMAIL HEADERS
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: " . $Name . "\r\n";
//YOUR MESSAGE CAN BE EMBEDDED WITH THE FIELDS U RECEIVE FROM FORM SUBMISSION
//SEND EMAIL
$sent = mail($to,$subject,$message,$headers,"-f $from")
if(mail($to,$subject,$message,$headers,"-f $from"))
{
Your information has been successfully sent to Stello Home Services. We will contact you shortly.
}
else
{
Your information was unsuccessfully sent. Please try again!
}
?>