When a user inputs their email on a form on my site, I get an email with their info. I'd like to be able to reply to that email and have their email autofill in "To:" but I'm having trouble. I found this question and tried the solution: reply-to address in php contact form but it's not working for me, and I'm not sure why.
Here is my PHP:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$to = 'amanda#myemail.com';
$headers = "BCC: clients#myemail.com\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$subject = '*** Quote Request';
$name = $_POST['name'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$passengers = $_POST['passengers'];
$service = $_POST['service'];
$email = $_POST['email'];
$message = <<<EMAIL
Quote submission from: $name
Name: $name
Phone Number: $phone
Date: $date
Time: $time
Pickup Location: $pickup
Drop Off Location: $dropoff
Total Passengers: $passengers
Service needed: $service
Email: $email
EMAIL;
if($_POST) {
mail($to, $subject, $message, $headers);
}
header('Location: thankyou.html');
exit();
?>
And this is the error message I'm getting, summed up:
Undefined variable: email in /contact-form-handler.php on line 9 Warning: Cannot modify header information - headers already sent by (output started at /contact-form-handler.php:9) in /contact-form-handler.php on line 44
The problem is the variable $email because if I put a Reply-To and specify an email, it works. I thought maybe it was because the variable is defined after I call it in the header, but adding it to the bottom didn't work. I'm a rookie with PHP so I'm not sure why this variable isn't working.
I also tried:
$headers = "BCC: clients#myemail.com\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Any help would be appreciated!
You use a variable before you define it!
Move this block to the top of your script:
$name = $_POST['name'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$passengers = $_POST['passengers'];
$service = $_POST['service'];
$email = $_POST['email'];
Like that:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$name = $_POST['name'];
$phone = $_POST['phone'];
$date = $_POST['date'];
$time = $_POST['time'];
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$passengers = $_POST['passengers'];
$service = $_POST['service'];
$email = $_POST['email'];
$to = 'amanda#myemail.com';
$headers = "BCC: clients#myemail.com\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$subject = '*** Quote Request';
$message = <<<EMAIL
Quote submission from: $name
Name: $name
Phone Number: $phone
Date: $date
Time: $time
Pickup Location: $pickup
Drop Off Location: $dropoff
Total Passengers: $passengers
Service needed: $service
Email: $email
EMAIL;
if($_POST) {
mail($to, $subject, $message, $headers);
}
header('Location: thankyou.html');
exit();
?>
seems like you don't receive $_POST['email']; from your contact form (re: "Undefined variable: email ")
check the name of your mail input field...
Related
I have problem with UTF-8 coding in mail.
I have simple code, but every time if send mail its problem with polish sings.
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$date = $_POST['date'];
$time = $_POST['time'];
$select = $_POST['select'];
$subject = $_POST['email'];
$mailTo = "moje#op.pl";
$headers = "From: ".$mailFrom;
$headers = "Content-Type: text/html; charset=UTF-8";
$body = "Dane kontaktowe: $name.\n".
"Email: $mailFrom.\n".
"Data: $date.\n".
"Godzina: $time.\n".
"Zabieg: $select.\n";
mail($mailTo, $subject, utf8_encode($body), $headers);
header("Location: reserv.php?mailsend");
}
?>
<?php
if(isset($_POST['submit']))
{
$email=$_POST['email'];
$comment=$_POST['comment'];
$captcha=$_POST['g-recaptcha-response'];
if(!$captcha)
{
echo 'Please check the the captcha form.';
}
$response=file_get_contents("https://www.google.com/recaptcha/api/sitev erify?secret="secretkey" &response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
header('Location:http://mywebsite.com/.errordocs/404.html');
}
else
{
header('Location:http://mywebsite.com/thankyou.php');
}
}
if (isset ($_POST['Side_Form'])){
$name = $_POST['name'];
$last = $_POST['last'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with Enjoy's contact e-mail)
$to = 'somebody#somewhere.com';
$subject = "Main Contact Form";
$message = "Name: $name
Email: $email
Phone: $phone
Comments: $comments";
$headers = "From: $email \r\n";
mail($to, $subject, $message, $headers);
}
?>
The problem is when the recaptcha is verified on the form, it displays the checkmark, user can click submit, but I get a blank screen and email doesn't send. Any help is Greatly appreciated, have been working on this for about 3 weeks.
your currently redirecting before actually sending the email. here is your code restructured. also fixed the recaptcha response processing
<?php
if (isset($_POST['submit'])){
$email = $_POST['email'];
$comment = $_POST['comment'];
$captcha = $_POST['g-recaptcha-response'];
if (! $captcha){
echo 'Please check the the captcha form.';
exit();
}else{
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretkey . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
$responseKeys = json_decode($response,true);
if (intval($responseKeys["success"]) !== 1){
header('Location:http://mywebsite.com/.errordocs/404.html');
exit();
}else{
if (isset($_POST['Side_Form'])){//not sure what this is, hopefully you do :-)
$name = $_POST['name'];
$last = $_POST['last'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with Enjoy's contact e-mail)
$to = 'somebody#somewhere.com';
$subject = "Main Contact Form";
$message = "Name: $name
Email: $email
Phone: $phone
Comments: $comments";
$headers = "From: $email \r\n";
mail($to,$subject,$message,$headers);
header('Location:http://mywebsite.com/thankyou.php');
exit();
}
}
}
}
?>
I am struggling with the following.When a user fills in a form looking like this, the inquiry gets sent to us to follow up the lead, but I need to find a way to modify my email script to send a confirmation email to the user aswell
My email script looks like this:
MY QUESTION HOW DO I MODIFY THIS TO SEND A THANK YOU CONFIRMATION TO THE USER
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$eventType = $_POST['eventType'];
$nrGuests = $_POST['nrGuests'];
$state = $_POST['state'];
$suburb = $_POST['suburb'];
$msg = $_POST['msg'];
$refferal_page = $_POST['page'];
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($refferal_page)){
$refferal_page="Source Unknown";
}
$to_email = "unknown#yahoo.co.nz"; //Recipient email
//TODO Sanitize input data using PHP filter_var().
$suburb = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
$subject = "You Have a New Booking!";
//Add booking INFO here;
$message = "A new Enquiry has been received from http://www.xxxxx.com.au. Please find details below and follow up:";
//email body
$message_body = $message."\r\n\r\n".$name."\r\nEmail : ".$email."\r\nPhone Number : ". $mobile."\r\nEvent Type: ".$eventType."\r\nNumber Guests:".$nrGuests."\r\nState: ".$state."\r\nSuburb:".$suburb."\r\nIP ADDRESS:".$ip."\r\nMessage:".$msg."\r\nReferal Page Source:".$refferal_page;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if($send_mail)
{
echo '<h1 class="page-header">Enquiry Successfully submitted</h1>';
}
else if(!$send_mail){
echo'<h1 class="page-header" style="color:RED">OOPS...SOMETHING WENT WRONG, PLEASE TRY AGAIN!</h1>';
}
}//server request method
else{
echo'<h1 style="color:red">SUBMIT A FORM PLEASE!</h1>';
}
?>
EMAIL THAT COMES TO US
A new Inqury has been received from www.xxxx.com.au. Please find details below and follow up:
FROM: Ryan XXX
Email : aass#testms.com
Phone Number : 334533
Event Type: Aniversary
Nr Guests: 34
State: Melbourne
Suburb: XYZ
IP ADDR: 162.111.255.111
MSG: this is a test. please disregard
Referal Page Source:aniversary
Obviously I dont want user to see this I just want to add something like "Thank you we will get back to you soon"
Any idea how I can modify the above script for us to get inquiry form but also for user to get an confirmation email?
Any help greatly appreciated
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$eventType = $_POST['eventType'];
$nrGuests = $_POST['nrGuests'];
$state = $_POST['state'];
$suburb = $_POST['suburb'];
$msg = $_POST['msg'];
$refferal_page = $_POST['page'];
$ip = $_SERVER['REMOTE_ADDR'];
if(!isset($refferal_page)){
$refferal_page="Source Unknown";
}
$to_email = "unknown#yahoo.co.nz"; //Recipient email
//TODO Sanitize input data using PHP filter_var().
$suburb = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
$subject = "You Have a New Booking!";
//Add booking INFO here;
$message = "A new Enquiry has been received from http://www.xxxxx.com.au. Please find details below and follow up:";
//email body
$message_body = $message."\r\n\r\n".$name."\r\nEmail : ".$email."\r\nPhone Number : ". $mobile."\r\nEvent Type: ".$eventType."\r\nNumber Guests:".$nrGuests."\r\nState: ".$state."\r\nSuburb:".$suburb."\r\nIP ADDRESS:".$ip."\r\nMessage:".$msg."\r\nReferal Page Source:".$refferal_page;
//proceed with PHP email.
$headers = 'From: '.$name.'' . "\r\n" .
'Reply-To: '.$email.'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if($send_mail)
{
echo '<h1 class="page-header">Enquiry Successfully submitted</h1>';
$EmailTo = $email;
$subject = "recipient subject";
$message_body = "Hi ".$name."recipient message";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: yourname<$youremail>\n";
$send_cust_mail = mail($to_email, $subject, $message_body, $headers);
}
else if(!$send_mail){
echo'<h1 class="page-header" style="color:RED">OOPS...SOMETHING WENT WRONG, PLEASE TRY AGAIN!</h1>';
}
}//server request method
else{
echo'<h1 style="color:red">SUBMIT A FORM PLEASE!</h1>';
}
?>
I am trying to display two concatenated variables in a subject line through an mailer.php page, but the subject line in the email always comes in blank. Below is the pertinent code.
/* Subject and To */
$to = 'nnorman#dimplexthermal.com';
$subject = $company . ' ' . $name;
/* Gathering Data Variables */
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Company: $company <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($to, $subject, $body, $headers);
$to = 'nnorman#dimplexthermal.com';
$subject = $company . ' ' . $name;
/* Gathering Data Variables */
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
You're not setting $company and $name until after you use them in $subject
Try switching the lines round:
/* Gathering Data Variables */
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$to = 'nnorman#dimplexthermal.com';
$subject = $company . ' ' . $name;
I am using a simple contact form and script on a website. The only issue I have is that I would like the email of the person filling out the form used as the reply to e-mail address rather than my servers address when I receive their submission. This is so I can simply reply to the contact rather than having to copy and paste their address and start a new reply to e-mail.
Any simple way to do this?
The below is the simple code I am using.
<?php
header('Location: http://XXXXXXXXXXXXXXXXX/contact.html');
$name = $_REQUEST['Person'];
$company = $_REQUEST['company'];
$address = $_REQUEST['address'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zip = $_REQUEST['zip'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$subject = $_REQUEST['subject'];
$details = $_REQUEST ['details'];
$byphone = $_REQUEST ['Phonebox'];
$emailbox = $_REQUEST['Emailbox'];
$message = "From $name\n Company $company\n Address $address\n $city $state $zip\n Email $email\n Phone $phone\n Subject $subject\n\n Details $details\n\n Contact by $byphone $emailbox";
mail ("XXXXXXXXX.com", "Customer Inquiry", "$message", "$email");
?>
Check this out: http://php.net/manual/en/function.mail.php
(Example below)
<?php
$to = 'server_owner#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: i_filled_the_form#example.com' . "\r\n" .
'Reply-To: i_filled_the_form#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>