| | |
PHP e-mail copy to viewer themselves ???
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
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:
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]<?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 = "";
}
?>
[/php]
What I've done, additionally, with the hope of sending copy to viewers is:
>> created a new variable "bcc"
$bcc=$_POST['email'];
AND added "$bcc" in my mail function by:
(mail($to, $_POST['inquiry'], $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"
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:
PHP Syntax (Toggle Plain Text)
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]<?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 = "";
}
?>
[/php]
What I've done, additionally, with the hope of sending copy to viewers is:
>> created a new variable "bcc"
$bcc=$_POST['email'];
AND added "$bcc" in my mail function by:
(mail($to, $_POST['inquiry'], $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"
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
The BCC is part of header:
[php]$headers="From: " . $_POST['email'] . "\r\n" .
"Inquiry: " . $_POST['inquiry'] . "\r\n" .
// ect etc
"Contact: " . $_POST['contact'];
"BCC: " . $_POST['email'];
[/php]
However, I don't think this is a good idea, and some mail server block it (typically AOL). What I suggest is send email twice - one to yourself and the other to your site visitor:
[php]
$header1 = "your header 1 info here";
$header2 = "your header 2 info here";
$to_myself = "your email address";
$to_visitor = $_POST["email"];
$common_data = "info post by the visitor here";
$thank_you = "your thank you paragraph here.\n\n".$common_data;
mail($to_myself, "title here", $common_data, $header1);
mail($to_visitor, "title here", $thank_you, $header2);
[/php]
I hope this help.
[php]$headers="From: " . $_POST['email'] . "\r\n" .
"Inquiry: " . $_POST['inquiry'] . "\r\n" .
// ect etc
"Contact: " . $_POST['contact'];
"BCC: " . $_POST['email'];
[/php]
However, I don't think this is a good idea, and some mail server block it (typically AOL). What I suggest is send email twice - one to yourself and the other to your site visitor:
[php]
$header1 = "your header 1 info here";
$header2 = "your header 2 info here";
$to_myself = "your email address";
$to_visitor = $_POST["email"];
$common_data = "info post by the visitor here";
$thank_you = "your thank you paragraph here.\n\n".$common_data;
mail($to_myself, "title here", $common_data, $header1);
mail($to_visitor, "title here", $thank_you, $header2);
[/php]
I hope this help.
Ecommerce-Web-Store.com Building Your e-Business.
•
•
•
•
Originally Posted by zippee
The BCC is part of header:
[php]$headers="From: " . $_POST['email'] . "\r\n" .
"Inquiry: " . $_POST['inquiry'] . "\r\n" .
// ect etc
"Contact: " . $_POST['contact'];
"BCC: " . $_POST['email'];
[/php]
However, I don't think this is a good idea, and some mail server block it (typically AOL). What I suggest is send email twice - one to yourself and the other to your site visitor:
[php]
$header1 = "your header 1 info here";
$header2 = "your header 2 info here";
$to_myself = "your email address";
$to_visitor = $_POST["email"];
$common_data = "info post by the visitor here";
$thank_you = "your thank you paragraph here.\n\n".$common_data;
mail($to_myself, "title here", $common_data, $header1);
mail($to_visitor, "title here", $thank_you, $header2);
[/php]
I hope this help.
Since you mentioned it's not quite a good idea, I'll get rid of Bcc & use your given format, which is rather easy & straightforward to understand.
So far, I have been receiving e-mail, but that's EXACTLY same as my viewer's copy, but knowing that I could have 2 different e-mail format for viewers & myself, it simply marvellous, since in my own format, I could make bit of changes, which I can't think of any presently but should do, once I delve into it further.
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
![]() |
Similar Threads
- Sending HTML email via PHP mail function (PHP)
- PHP Mail with Sender ID (PHP)
- Problems with PHP mail function. (PHP)
- php mail form - need to redirect to new page (PHP)
- how do you setup php mail()? using sendmail and yellowdog linux w/apache and php4 (*nix Software)
Other Threads in the PHP Forum
- Previous Thread: I want to let members message each other
- Next Thread: Convert a string to an integer
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





