I've adapted a simple contact form using php which works fine. However I now need to add an auto response email, so when the client has entered details into the form it not only sends me the details, but sends the client a html email response.
Can any of you kind clever people point me in the right direction on how to achieve this as I'm stuck. Below is the code I'm using; am I right in thinking I need to use another "if" statement to send auto reply?
Any help will be greatly appreciated
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$to = 'andy@andydry.com';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact
form.
"."Here are the details:
Name: $name
Email:
$email_address
Phone: $phone
Message:
$message";
$headers = "From: noreply@yourdomain.com
";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
First off, a caveat: the php mail() function is prone to header-injection abuse, which can be used to force your mail server to spam emails on spammers behalf. Strictly filter incoming email addresses
As far as your question, you seem to be wanting to add a CC to your email of the customer's email address.
That is done through adding to the headers:
$headers .= "CC: ".$customer_email_address_sanitized_and_escaped."
";
Send another email, but to the client, when the first email is sent successfully. That is assuming you're sending the client an email with different content than you're sending yourself when they use the contact form. Otherwise, use BCC.
Also, use a mail library such as Swiftmailer.