My Contact form on my website www.allinclusivewebdesign.co.uk does the job well. However, as the time went by, I've been thinking to make it do MORE than just a basic form, allowing me to receive the information viewers' submits (as it does perfectly well, at the moment).
I wonder if anyone could point me in the right direction, as how could I possibly send a "Bcc" to the viewer who fill the form in with message saying:
Thanks for contacting us. We'll be in touch soon (if you've asked to be contacted).
Following are the details you've sent:
(these details would be be exactly same as I receive i.e. all the details from the field).
Please visit us soon for your bespoke web solution.
Regards,
www.allinclusivewebdesign.co.uk
Now, I reckon the above message could be saved in one new variable, so I could do my editing in the message along with some formatting, etc. & THEN recall this "email confirmation" variable at some point, if such a thing is attainable.
My present PHP code is:
<?php
// If the form has been posted, analyse it:
if ($_POST) { // CURLY BRACKET (Open): After Clicking Submit
foreach ($_POST as $field => $value) {
$value = trim($value);
}
// Creating Variables
$to="contact@allinclusivewebdesign.byethost13.com";
$inquiry=$_POST['inquiry'];
$title=$_POST['title'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=stripslashes($_POST['message']);
$reply=$_POST['reply'];
$contact=$_POST['contact'];
$headers="From: " . $_POST['email'] . "\r\n" .
"Inquiry: " . $_POST['inquiry'] . "\r\n" .
"Title: " . $_POST['title'] . "\r\n" .
"First Name: " . $_POST['first_name'] . "\r\n" .
"Last Name: " . $_POST['last_name'] . "\r\n" .
"E-mail: " . $_POST['email'] . "\r\n" .
"Phone: " . $_POST['phone'] . "\r\n" .
"Reply: " . $_POST['reply'] . "\r\n" .
"Contact: " . $_POST['contact'];
// Create empty ERROR variables
$error = ""; // for fields left BLANK
$errorflag = ""; // for fields with INVALID data entered
// Check for field/fields that is/are left BLANK
if (($first_name == "") || ($last_name == "") || ($email == "") || ($phone == "") || ($message == "")) { // CURLY BRACKET (Open): For Validating if fields are left blank
$error = "<span class='colorTextBlue'>Please fill in all fields!</span>";
} // CURLY BRACKET (Close): For Validating if fields are left blank
else { // CURLY BRACKET (Open): Form Validation
// Validate First Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
if (ctype_alpha($first_name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid First Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag= "first_name";
}
// Validate Last Name (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (ctype_alpha($last_name) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Last Name <span class='italic'>(Alphabets only)</span></span>";
$errorflag="last_name";
}
// Validate E-mail (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if ((strpos($email, "@") == FALSE)||
(strpos($email, ".") == FALSE) ||
(strpos($email, " ") != FALSE)) {
$error = "<span class='colorTextBlue'>Please enter a valid E-mail</span>";
$errorflag="email";
}
// Validate Contact No. (including ERRORS such as (1) field left BLANK (2) field with INVALID data entered
else if (is_numeric($phone) == FALSE) {
$error = "<span class='colorTextBlue'>Please enter a valid Contact No. <span class='italic'>(must contain numbers only, without any space)</span></span>";
$errorflag="phone";
}
} // CURLY BRACKET (Close): Form Validation
// Confirmation Message seen AFTER filling the form and pressing "Submit" button (whether there's an error or not)
// If there's an error along with displaying the list of flagged error/errors
if ($error != "") { // CURLY BRACKET (Open): For Error
echo "<br/> <b><span class='colorTextRed'>Error Occured: </b>" . $error."</span>" ;
} // CURLY BRACKET (Close): For Error
// If there's NO error at all, along with displaying the filled fields
else if (mail($to, $_POST['inquiry'], $message, $headers))
{
echo "<p><span class='colorTextBlue'>E-mail sent successfully</span></p>";
echo "<p>Thanks for your comment and time. We will be in touch with you shortly, if required. Following are the details you filled in.<br/><br/>";
echo "<b>Nature of Inquiry:</b> ". $inquiry . "<br/>";
echo "<b>Title:</b> ". $title . "<br/>";
echo "<b>First Name:</b> ". $first_name . "<br/>";
echo "<b>Last Name:</b> ". $last_name . "<br/>";
echo "<b>E-mail:</b> ". $email . "<br/>";
echo "<b>Contact No.:</b> ". $phone . "<br/>";
echo "<b>Message:</b> ". $message . "<br/>";
echo "<b>Reply:</b> ". $reply . "<br/>";
echo "<b>Contact Method:</b> ". $contact . "<br/></p>";
}
else {
$error = "<span class='colorTextRed'> E-mail NOT sent</span>";
}
} // CURLY BRACKET (Close): After Clicking Submit
// Displays the Empty variables i.e. when the Contact Form appears completely blank for the VERY FIRST time with all blank fields
else {
$inquiry = "";
$title = "";
$first_name = "";
$last_name = "";
$email = "";
$phone = "";
$message = "";
$reply = "";
$contact = "";
$errorflag = "";
}
?>
What I've done, additionally, with the hope of sending copy to viewers is:
>> created a new variable "bcc"
$bcc=$_POST;
AND added "$bcc" in my mail function by:
(mail($to, $_POST, $message, $headers, $bcc))
This DID NOT work, when I tested the form.
Anyhow, would I need a "bcc" OR "cc" in this case. I reckon, it should be "bcc" since I don't want viewers to know that I'm receiving my mails on "contact@allinclusivewebdesign.byethost13.com"