I have a contact form and I am using the below PHP Script to get emails from my contact form. I want to send a copy of the same email to the sender email also. Can anyone help me?. Thank you!
<?php
$errors = '';
$myemail = '[email protected], [email protected]';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['subject']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Message from: $name";
$email_body = "New message received. ".
" Here are the details:\n \n NAME: $name \n
SUBJECT: $subject \n
EMAIL ADD: $email_address \n
MESSAGE: $message";
$headers = "From: $email_address\n";
//$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-us.php');
}
?>
You can use cc n header
More idea