2017-12-19 8 views
1

이 코드를 가지고 : 위의 내 코드에 그대로 선으로 이메일 라인을 보낼 수 있지만, 죄송합니다, 단지 오전

<?php 
$emails = '[email protected],[email protected]'; 
$emailsSplitted = explode(',', $emails); 

foreach ($emailsSplitted as $email) { 
    $to ='$email'; 
    $message = 'send this to all email above'; 
    $subject = 'the subject'; 
    $headers = 'From: [email protected]'; 
    mail($to, $subject,$message, $headers); 
} 
$str = "[email protected][thanks][email protected][i want also][email protected][multiple msg]"; 
$regExpresion = "/(.*?)\[(.*?)\]/"; 

preg_match_all($regExpresion, $str, $aMatches, PREG_SET_ORDER, 0); 
foreach ($aMatches as $aMail){ 
    $to = $aMail[1]; 
    $message = $aMail[2]; 
    $subject = 'the subject'; 
    $headers = 'From: [email protected]'; 
    mail($to, $subject,$message, $headers); 
} 
$to = '[email protected]'; 
$message = 'single message'; 
$subject = 'the subject'; 
$headers = 'From: [email protected]'; 
mail($to, $subject, $message, $headers); 

각 문자열 레코드에 대해 수행하는 것보다이 기능을 제공하기 위해 메일 기능 행을 하나만 사용할 수 있는지 알고 싶습니다. 감사

답변

0

예는 단순히 첫 번째 매개 변수로 메일() 함수에 $ 이메일 변수를 전달

http://php.net/manual/en/function.mail.php

을 참조 이메일 앤 쉼표로 구분 된 문자열을 사용할 수 있습니다.

는 그래서는 다음과 같습니다

$emails = '[email protected],[email protected]'; 

$message = 'send this to all email above'; 
$subject = 'the subject'; 
$headers = 'From: [email protected]'; 

mail($emails, $subject,$message, $headers); 
+0

내가 전자보고 싶지 않은 것을 : '@ example.com, EMAIL2 @ example.com 이메일 1'= g $ 이메일을; $ emailsSplitted = 폭발 (',', $ 이메일); foreach ($ emails로 $ 이메일) { $ to = '$ email'; $ message '예. 원합니다'; $ str = "[email protected] [감사] [email protected] [i want also] [email protected] [여러 메일]"; $ regExpresion = "/(.*?)\[(.*?)\]/"; preg_match_all ($ regExpresion, $ str, $ aMatches, PREG_SET_ORDER, 0); foreach ($ aMatches as $ aMail) { $ to = $ aMail [1]; $ message = $ aMail [2]; $ subject = 'the subject'; $ headers = '보낸 사람 : [email protected]'; mail ($ to, $ subject, $ message, $ headers); } } – user9107323