从在线表单发送报告给客户,告诉他选择的所有数据?

时间:2013-02-25 16:03:58

标签: php html

我是这个领域的初学者 我已经为客户提交了一份提交表格来销售一些产品 我从表单到我的电子邮件中收到客户输入的数据。 但是我希望客户能够根据客户在[电子邮件地址:]

字段中输入的电子邮件地址,向他发送相同的数据电子邮件。

我的PHP代码是:

<?php
if(isset($_POST['email'])) {

    $email_to = "HERE I PUT MY EMAIL";
    $email_subject = "You've got a message - Online Form";


    function died($error) {
        echo "We are very sorry, but ";
        echo $error."<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['phone']) ||
        !isset($_POST['face_cream']) ||
        !isset($_POST['body_cream']) ||
        !isset($_POST['body_oil']) ||
        !isset($_POST['face_wash']) ||
        !isset($_POST['breast_oil']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $phone = $_POST['phone']; // required
    $face_cream = $_POST['face_cream']; // not required
    $body_cream = $_POST['body_cream']; // not required
    $body_oil = $_POST['body_oil']; // not required
    $face_wash = $_POST['face_wash']; // not required
    $breast_oil = $_POST['breast_oil']; // not required
    $comments = $_POST['comments']; // not required
    $agreement = $_POST['agreement']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
 if(strlen($phone) < 6) {
    $error_message .= 'The Phone Number you entered do not appear to be valid.<br />';
  }
 if(strlen($agreement) < yes) {
    $error_message .= 'The agreement you entered do not appear to be valid.<br />';
  }
if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Phone Number: ".clean_string($phone)."\n";
    $email_message .= "The chosen quantity of (Face Cream) is: ".clean_string($face_cream)."\n";
    $email_message .= "The chosen quantity of (Body Cream) is: ".clean_string($body_cream)."\n";
    $email_message .= "The chosen quantity of (Body Oil) is: ".clean_string($body_oil)."\n";
    $email_message .= "The chosen quantity of (Face Wash) is: ".clean_string($face_wash)."\n";
    $email_message .= "The chosen quantity of (Breast Oil) is: ".clean_string($breast_oil)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";



// checkbox
if(isset($_POST['agreement']) &&
   $_POST['agreement'] == 'yes')
{
    echo "You've accepted our terms and conditions.<br>";
}
else
{
    echo "You didn't agree on the Terms & Conditions.<br>";
}   



// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>

(提前谢谢)

1 个答案:

答案 0 :(得分:0)

您只需要另一个@mail命令,即可撤消email_from和email_to

...... all your d**kload of code
@mail($email_to, $email_subject, $email_message, $headers);  // Sends to YOU
@mail($email_from, $email_subject, $email_message, $headers); // Sends to the client

您未来的问题:

  1. 这些代码都不是由您编写的(如果是,您应该知道该怎么做)。
  2. 您复制了整个代码,因为(参见问题1)
  3. 你没有清楚地解释问题是什么
  4. 现在。如果这是你想要的。请单击“接受答案”勾选以帮助构建一些好的Karma