Houdini wrote:To send a Bcc: in your mail you would just include it in the $headers of your email. Here is the list of HEADERS that comprise an E-mail with a short description'
Your Headers in the $headers need to be rethought to sucessfully send e-mail with the proper headers. Out of your headers shown below
$headers="From: " . $_POST['email'] . "\r\n" .//valid header
"Inquiry: " . $_POST['inquiry'] . "\r\n" .//not a valid header
"Title: " . $_POST['title'] . "\r\n" . //not a valid header
"First Name: " . $_POST['first_name'] . "\r\n" .//not a valid header
"Last Name: " . $_POST['last_name'] . "\r\n" .//not a valid header
"E-mail: " . $_POST['email'] . "\r\n" .//not a valid header
"Phone: " . $_POST['phone'] . "\r\n" .//not a valid header
"Reply: " . $_POST['reply'] . "\r\n" .//If it were Reply-to it would be valid
"Contact: " . $_POST['contact'];//not a valid header
Just put the Bcc: in you $headers and you might want to use the Inquiry, Title, First Name etcetera within the body of the message. mail()Has 5 parameters and three are required and the other two are optional but the addtitional headers is usually used. (Mostly for the From: address). This is from the manual as to why the $bcc did not work!
That was fantastic, since it worked perfectly well. I can see the mail reaching me AND a confirmation message sent to the sender, as well.
Bearing in mind, your suggestion, I've altered my codes accordingly (including "$error AND $errorflag's recommendation. Although, I'm afraid, I didn't quite understand what you meant by "it'll list ONLY the last error". Do you mean, if someone type in TWO fields wrong i.e. "name & e-mail" then BOTH would display at the same time, since right now ONLY one displays & once we correct it, the OTHER displays thereafter, so "Error Occured" ONLY displays ONE error at a time, EVEN after I use ".=":
<?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']) . "\r\n" .
"From: " . $_POST['email'] . "\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'];
$reply=$_POST['reply'];
$contact=$_POST['contact'];
$headers="From: " . $_POST['email'] . "\r\n" .
"Bcc: " . $_POST['email'];
// 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><br />";
$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><br />";
$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><br />";
$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><br />";
$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, "www.allinclusivewebdesign.co.uk 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. Copy of your Inquiry has been sent to your e-mail.<br/>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 = "";
}
?>
Once the submit is pressed the screen looks like in the attached file (with all details being displayed in "message" field. Try filling the form yourself & you'd know what I mean.
In addition, just certain things I wonder if you could enlighten me about.
I've tried & tested it, it works well. Only tiny hiccup is........ EVEN I receive exactly the same message, ALONG WITH the viewer himself (which is fine).
Is there anyway, I could NOT receive the "copy" of this "confirmation" e-mail, since I'd end-up with having "loads of" these confirmation messages, which is NOT relevant for me to receive it, since it's MORE of a relevance to viewers THEMSELVES.
Lastly, when if you fill this form yourself, you'll now get the "copy" of your own message, BUT when you receive it, you'll have "contact@allinclusivewebdesign.byethost13.com" in the "to" field & your own e-mail address in the "from" field, which looks not quite professional, since it'll give viewers the impression that they've received the form from "their OWN address" from "my website", if you catch my drift.
Is there anyway, I could make changes here, such as having "viewer's OWN e-mail" (whatever they type in the "e-mail" field) in the "to" field AND "my e-mail" i.e. "contact@allinclusivewebdesign.byethost13.com" in the "from" field.