发送电子邮件两个多个收件人,但不同的身体使用PHP
问题描述:
我有一个联系表格,当用户提交所有的价值将发送(电子邮件)给admin.But现在我想做的时候用户提交管理员将收到电子邮件和用户也将收到一封电子邮件,但身体不同。发送电子邮件两个多个收件人,但不同的身体使用PHP
这里我以前的代码:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$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._%-][email protected][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.
<?
}
?>
答
just concatenate
$email_to = ' [email protected] ' . ',' ;
$email_to . = ' [email protected] ' ;
+0
供参考:您的答案不适用于该人询问的内容。 Biswajit的建议/答案是解决问题的方法。 – 2013-03-23 15:00:22
答
在您可以将其发送给管理员发送后第二个邮件有不同的主题,EMAIL_TO,email_message以同样的方式。
+0
感谢Biswajid.It的工作! – herbie 2013-03-25 08:33:39
发送两个邮件与两个主体 – 2013-03-23 09:51:22
可能的重复 - http://stackoverflow.com/questions/9510030/how-to-do-email-form-with-multiple-recipients-and-different-body。看看这个问题。 – Boris 2013-03-23 09:52:04
您是否找到了解决方案? – 2013-03-23 14:39:15