Jump to content

PHP e-mail copy to viewer themselves ???


j4mes_bond25

Recommended Posts

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/>&nbsp;&nbsp;&nbsp;<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'>&nbsp;&nbsp;&nbsp;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 = "";
}
?>
[/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"
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.