j4mes_bond25 Posted July 9, 2006 Share Posted July 9, 2006 My Contact form on my website [url=http://www.allinclusivewebdesign.co.uk]www.allinclusivewebdesign.co.uk[/url] 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: [CODE]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[/CODE]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: [code=php:0]<?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 fieldselse { $inquiry = ""; $title = ""; $first_name = ""; $last_name = ""; $email = ""; $phone = ""; $message = ""; $reply = ""; $contact = ""; $errorflag = "";}?>[/code]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" Quote Link to comment https://forums.phpfreaks.com/topic/14087-php-e-mail-copy-to-viewer-themselves/ Share on other sites More sharing options...
ShogunWarrior Posted July 9, 2006 Share Posted July 9, 2006 BCC is for sending a copy of the email to someone else, you are sending two separate,different emails so you can't BCC. Also, to included a header you must include it in the string $headers so if you wanted to BCC them with the email that YOU will get then you would do this I believe:[code]$headers = "Bcc:theiremail@domain.com";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14087-php-e-mail-copy-to-viewer-themselves/#findComment-55132 Share on other sites More sharing options...
Daniel0 Posted July 9, 2006 Share Posted July 9, 2006 Heh, just noticed the line saying [code]if ($_POST) { // CURLY BRACKET (Open): After Clicking Submit[/code].$_POST is always true... you should do something like [code]if(count($_POST) > 0) {[/code] instead. Quote Link to comment https://forums.phpfreaks.com/topic/14087-php-e-mail-copy-to-viewer-themselves/#findComment-55191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.