2017-10-30 4 views
-1

나는 관리자와 사용자 모두에게 다른 이메일을 보내고 싶습니다. 그 방법을 모릅니다. 내가 당신과 공유하는 코드는 관리자와 사용자 모두에게 동일한 이메일을 보내고 있습니다. 제발 도와주세요. 제발 ..PHP에서 관리자와 사용자에게 다른 메시지를 보내는 방법

여기 내 코드입니다;

$car = $_POST['category']; 
$pick = $_POST['text1']; 
$drop = $_POST['text2']; 
$source = $_POST['text3']; 
$email= $_POST['text4']; 

$to="$email"; 
$subject="Web Enquiry"; 
$message="Hi,". "\r\n" . "\r\n" . 
"You've received an email with following details, from the inquiry made at the website- [email protected]" ."\r\n"."\r\n". 
"Car Category:"." "."$car"."\r\n". 
"Source Location:"." "."$pick"."\r\n". 
"Destination Location:"." "."$drop"."\r\n". 
"Day and Time.:"." "."$source". "\r\n". 
"Email:"." "."$email". "\r\n" ."\r\n". 
"Thanks & Regards,". "\r\n" . 
"Web Admin"."\r\n" ; 

$headers ="From:$email\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 
$headers.="MIME-Version: 1.0\n"; 
$headers.="Content-type: text/html; charset=iso 8859-1"; 
if(mail($to, $subject, $message,$headers)) 
{ 
    echo "Your Message has been sent." ; 
} else { 
    echo ""; 
} 
+1

다른 변수를 보낼 때마다 'mail()'을 두 번 호출하십시오. – nogad

+0

데모를 어떻게 보여줄 수 있습니까? – Narinder

+1

메일 (_VARS 여기); 메일 (_DIFFIRENT_VARS 여기); – nogad

답변

2

mail() 함수를 두 번 호출해야합니다. 하나는 사용자 용이고 다른 하나는 admin 용입니다. 줄을 제거하십시오

$headers .= 'Cc: [email protected]' . "\r\n"; 

코드에서 제거하십시오. 그런 다음 사용자 및 관리자에 대해 서로 다른 메시지를 정의하십시오.

$to="$email"; 
    $subject="Web Enquiry"; 
    $message="....." //your message to user goes here 

    $to_admin = "[email protected]"; 
    $subject_admin = "...."; //subject for mail to admin 
    $message_admin = "....." //your message to admin goes here 

다른 이메일을 보내려면 mail() 함수를 두 번 사용하십시오.

if((mail($to, $subject, $message,$headers) && mail($to_admin, $subject_admin, $message_admin, $headers)) 
    { 
     echo "Your Message has been sent." ; 
    } else { 
     echo ""; 
    } 
+0

사용자 메일이 스팸 메일이 될 수 있습니다. 이유를 말해 줄 수 있습니까? – Narinder

+0

헤더에 MIME 버전을 추가하십시오. $ headers. = "MIME 버전 : 1.0 \ n"; $ headers. = "콘텐츠 유형 : text/html; charset = iso-8859-1 \ n"; – Bandana

+0

감사합니다. @ bandana. – Narinder

0

먼저 사용자 또는 관리자인지 확인해야합니다. 그가 사용자 인 경우 admin을위한 조건문을 추가 할 수 있습니다. 이와 같이 :

if($user_role == "user"){ 
    //mail for user 
    ..... 
} 
if($user_role == "admin"){ 
    //mail for admin 
    ..... 
} 

질문이 있으시면 언제든지 문의하십시오.