1

我是这个领域的初学者 我已经为客户制作了一个提交表格来销售一些产品 我从表格中收到消息到我的电子邮件中,其中包含客户输入的数据..但我希望客户得到根据客户在 [ 电子邮件地址: ] 字段中输入的电子邮件地址,将相同的数据发送给他

我的 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
}
?>

( 提前致谢 )

4

1 回答 1

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. 你没有清楚地解释问题是什么

现在。如果这是你想要的。请点击“接受答案”打勾以帮助建立一些好的业力

于 2013-02-25T20:23:31.637 回答