0

我有一个联系表格,当用户提交所有值时将发送(电子邮件)给管理员。但是现在我想做当用户提交管理员将收到电子邮件并且用户也将收到一封电子邮件但正文不同时。

这是我以前的代码:

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

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "admin@gmail.com";
$email_subject = "Lifemailer Sales Enquiry";
$email_to_user= "Name: ".clean_string($name)."\n";


function died($error) {
    // your error code can go here
    $URL = "error.html";
header("Location: $URL");
die();
}

// validation expected data exists
if(!isset($_POST['name']) ||
    !isset($_POST['contact']) ||
    !isset($_POST['email']) ||
    !isset($_POST['email_sub']) ||
    !isset($_POST['remarks'])) {
    died('We are sorry, but there appears to be a problem with the form your
     submitted.');      
}

$name = $_POST['name']; // not required
$contact = $_POST['contact']; // required
$email = $_POST['email']; // required
$email_sub = $_POST['email_sub']; // required
$remarks = $_POST['remarks']; // required


$error_message = "";
$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
 }
    $string_exp = "^[0-9 .-]+$";
  if(!eregi($string_exp,$contact)) {
$error_message .= 'The Contact Number you entered does not appear to be valid.
 <br     />';
  }
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email)) {
$error_message .= 'The Email Address you entered does 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 .= "Name: ".clean_string($name)."\n";
$email_message .= "Contact Number: ".clean_string($contact)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Email Subject : ".clean_string($email_sub)."\n";
$email_message .= "Remarks/Enquiry : ".clean_string($remarks)."\n";



    // create email headers
    $headers = 'From: '.$email."\r\n".
    'Reply-To: '.$email."\r\n" .
    'X-Mailer: PHP/' . phpversion();
     @mail($email_to, $email_subject, $email_message, $headers);  
     $URL = "thank-you.html";
     header("Location: $URL");



     ?>

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

     <?
      }
     ?>
4

2 回答 2

1

以同样的方式,您可以在将其发送给管理员后发送具有不同主题、email_to、email_message 的第二封邮件。

于 2013-03-23T11:15:00.663 回答
0
  just concatenate

  $email_to = ' admin@gmail.com ' . ',' ;

  $email_to  . = ' admin@gmail.com ' ;
于 2013-03-23T10:48:00.047 回答