2013-03-23 37 views
0

我有一個聯繫表格,當用戶提交所有的價值將發送(電子郵件)給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. 

    <? 
     } 
    ?> 
+0

發送兩個郵件與兩個主體 – 2013-03-23 09:51:22

+0

可能的重複 - http://stackoverflow.com/questions/9510030/how-to-do-email-form-with-multiple-recipients-and-different-body。看看這個問題。 – Boris 2013-03-23 09:52:04

+0

您是否找到了解決方案? – 2013-03-23 14:39:15

回答

0
just concatenate 

    $email_to = ' [email protected] ' . ',' ; 

    $email_to . = ' [email protected] ' ; 
+0

供參考:您的答案不適用於該人詢問的內容。 Biswajit的建議/答案是解決問題的方法。 – 2013-03-23 15:00:22

1

在您可以將其發送給管理員發送後第二個郵件有不同的主題,EMAIL_TO,email_message以同樣的方式。

+0

感謝Biswajid.It的工作! – herbie 2013-03-25 08:33:39

相關問題