Hi folks,
I am fairly new to PHP and I have hit a stumbling block regarding sending an email by PHP. I have created two simple PHP pages. The first is a page with some a couple of free text boxes and a couple of drop down lists. Users enter in text and choose options and press the submit button. Upon clicking the submit button it takes them to a verify page where an email is sent to an email address specified with field data passed through from the previous page. This is all fine and dandy. However today i received an email requesting that the person who entered in the details receives an email also. I will attach the code below to view;
This code works and sends all data from the fields on the previous page to the email address in the $to field. However I tried experimenting with adding in a free text field for users to enter in their email address, and have that pass through to the verify page. I amended the code to this;
However this throws an error and doesn't send an email to either address which is understandable. having either the defined email address or the variable work, just not both together which is what i am liking to happen. If anyone has any idea as-to where i am going wrong or whether its even possible, it would be greatly appreciated.
Many Thanks
I am fairly new to PHP and I have hit a stumbling block regarding sending an email by PHP. I have created two simple PHP pages. The first is a page with some a couple of free text boxes and a couple of drop down lists. Users enter in text and choose options and press the submit button. Upon clicking the submit button it takes them to a verify page where an email is sent to an email address specified with field data passed through from the previous page. This is all fine and dandy. However today i received an email requesting that the person who entered in the details receives an email also. I will attach the code below to view;
PHP:
<?php
$to = "[email protected]";
$subject = "Blah Blah";
$message = "blah blah blah";
$message .= "\n";
$message .= " ";
$message .= "\n";
$message .= "Name: ";
$message .= $_POST["FName"];
$message .= " ";
$message .= $_POST["SName"];
$message .= "\n";
$message .= "Date Of Birth: ";
$message .= $_POST["Day"];
$message .= "-";
$message .= $_POST["Month"];
$message .= "-";
$message .= $_POST["Year"];
$message .= "\n";
$message .= " ";
$message .= "\n";
$message .= "Monday 4th December: ";
$message .= $_POST["Course1"];
$message .= "\n";
$message .= "Tuesday 5th December: ";
$message .= $_POST["Course2"];
$message .= "\n";
$message .= "Wednesday 6th December: ";
$message .= $_POST["Course3"];
$message .= "\n";
$message .= "Monday 11th December: ";
$message .= $_POST["Course4"];
$message .= "\n";
$message .= "Tuesday 12th December: ";
$message .= $_POST["Course5"];
$message .= "\n";
$message .= "Wednesday 13th December: ";
$message .= $_POST["Course6"];
$message .= "\n";
$message .= "Thursday 14th December: ";
$message .= $_POST["Course7"];
$message .= "\n";
$message .= "\n";
$message .= "Additional Requirements: ";
$message .= $_POST["LLDD"];
$message .= "\n";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
This code works and sends all data from the fields on the previous page to the email address in the $to field. However I tried experimenting with adding in a free text field for users to enter in their email address, and have that pass through to the verify page. I amended the code to this;
PHP:
<?php
$to = $_POST["EmailAddress"], "[email protected]";
$subject = "Blah Blah";
$message = "blah blah blah";
$message .= "\n";
$message .= " ";
$message .= "\n";
$message .= "Name: ";
$message .= $_POST["FName"];
$message .= " ";
$message .= $_POST["SName"];
$message .= "\n";
$message .= "Date Of Birth: ";
$message .= $_POST["Day"];
$message .= "-";
$message .= $_POST["Month"];
$message .= "-";
$message .= $_POST["Year"];
$message .= "\n";
$message .= " ";
$message .= "\n";
$message .= "Monday 4th December: ";
$message .= $_POST["Course1"];
$message .= "\n";
$message .= "Tuesday 5th December: ";
$message .= $_POST["Course2"];
$message .= "\n";
$message .= "Wednesday 6th December: ";
$message .= $_POST["Course3"];
$message .= "\n";
$message .= "Monday 11th December: ";
$message .= $_POST["Course4"];
$message .= "\n";
$message .= "Tuesday 12th December: ";
$message .= $_POST["Course5"];
$message .= "\n";
$message .= "Wednesday 13th December: ";
$message .= $_POST["Course6"];
$message .= "\n";
$message .= "Thursday 14th December: ";
$message .= $_POST["Course7"];
$message .= "\n";
$message .= "\n";
$message .= "Additional Requirements: ";
$message .= $_POST["LLDD"];
$message .= "\n";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
However this throws an error and doesn't send an email to either address which is understandable. having either the defined email address or the variable work, just not both together which is what i am liking to happen. If anyone has any idea as-to where i am going wrong or whether its even possible, it would be greatly appreciated.
Many Thanks