我有这个代码:
<?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);
它就像在我上面的代码中一样逐行发送电子邮件,但很抱歉,只是想知道我是否可以只使用一个邮件功能线来为每个字符串记录执行此操作。谢谢
是的,您可以使用'逗号分隔的电子邮件字符串
请参阅http://php.net/manual/en/function.mail.php
只需将$ emails变量作为第一个参数传递给mail()函数即可。
所以它会是:
$emails = '[email protected],[email protected]';
$message = 'send this to all email above';
$subject = 'the subject';
$headers = 'From: [email protected]';
mail($emails, $subject,$message, $headers);