I have contact form. I'd like to add CC to e-mail: abc@abc.de and change e-mail sender. Currently it shows my server as a sender, I'd like to have reply-to form users.
Hello. I have contact form. I'd like to add CC to e-mail: abc@abc.de and change e-mail sender. Currently it shows my server as a sender, I'd like to have reply-to form users.
<?php
session_start();
//Ajax Questions Form
if(isset($_POST['email'])){
$name = $_POST['name'];
$email = $_POST['email'];
$arrival = $_POST['arrival'];
$departure = $_POST['departure'];
/// $adults = $_POST['adults'];
// $children = $_POST['children'];
// $room = $_POST['room'];
$requests = $_POST['requests'];
$to = 'contact@test.camp'; //Replace with recipient email address
$subject = 'Hotel Booking'; //Subject line for emails
$message = 'From: '.$name."
".'Email: '.$email."
".'Arrival: '.$arrival."
".'People: '.$departure; //."
".'Adults: '.$adults."
".'Children: '.$children."
".'Room: '.$room."
".'Requests: '.$requests;
// Mail Functions
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.
echo "Your email was sent!"; // success message
}
}
//Contact Php Form
if(isset($_POST['contact_email'])){
$contact_name = $_POST['contact_name'];
$email = $_POST['contact_email'];
$contact_message = $_POST['message'];
$to = 'marek@gmail.com'; //Replace with recipient email address
$subject = 'Contact Form'; //Subject line for emails
$message = 'From: '.$contact_name."
".'Email: '.$email."
".'Message: '.$contact_message;
// Mail Functions
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // This line checks that we have a valid email address
mail($to, $subject, $message) or die('Error sending Mail'); //This method sends the mail.
}
}
?>
For add CC or BCC or ReplyTo add header to your email structure :
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'To: andreas<mail1@gmail.com>, thomas<mail2@gmail.com>';
$headers[] = 'From: from <from@gmail.com>
Reply-to: <ReplyTo@gmail.com>';
$headers[] = 'Cc: Cc@gmail.com';
$headers[] = 'Bcc: Bcc@gmail.com';
mail($to, $subject, $message, implode("
", $headers));
The php mail function does not have much functionality try using something like PHPMailer which allows you to send more complex emails