Jump to content

Adding fields to the email header and personalized response


topolino

Recommended Posts

First off I want to add the $Surname field into the email header so it shows not just from Name but from Name and Surname, when the recipient receives the form data. Second, how can I make the PHP respond to this data by extracting the $Name and $Surname fields, such that the person filling it in receives an email saying Thank you $firstname $lastname for your recent testimonial.etc etc

 

Any help would be appreciated.

 

Here is the PHP code I am using:

 

<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
 
$Recipient = '[email protected]'; // <-- Set your email here
 
$subject = $_POST['subject'];
 
if($Recipient) {
 
$Name = $_POST['name'];
$Surname = $_POST['surname'];
$Email = $_POST['email'];
$Subject = $_POST['subject'];
$Message = $_POST['message'];
$Manufacturer = $_POST['manufacturer'];
$Model = $_POST['model'];
 
$Email_body = "";
$Email_body .= "First Name: " . $Name . "\n" .
  "Last Name: " . $Surname . "\n" .
  "Email Address: " . $Email . "\n" .
  "Subject: " . $Subject . "\n" .
  "Testimonial: " . $Message . "\n" .
  "Motorcycle Make: " . $Manufacturer . "\n" .
  "Motorcycle Model: " . $Model . "\n";
 
$Email_headers = "";
$Email_headers .= 'From: ' . $Name . ' <' . $Email . '>' . "\r\n".
 "Reply-To: " .  $Email . "\r\n";
 
$sent = mail($Recipient, $Subject, $Email_body, $Email_headers);
 
if ($sent){
$emailResult = array ('sent'=>'yes');
} else{
$emailResult = array ('sent'=>'no');
}
 
echo json_encode($emailResult);
 
} else {
 
$emailResult = array ('sent'=>'no');
echo json_encode($emailResult);
 
}
?>
 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.