如何向字符串中的多个电子邮件发送一条消息

时间:2017-12-17 20:21:13

标签: php string email send

我有一个字符串:

  $email = 'xyz@email.com,abc@email.Com,and others@email.com'; 
AND
  $msg = 'SEND these to each email above thanks';

在我的成就中,我希望能够将$ msg中的文本作为电子邮件发送到$ email示例中的每封电子邮件中:

  $to = 'xyz@email.com';
  $msg = 'SEND these to each email above thanks';
  $to = 'abc@email.com';
  $msg = 'SEND these to each email above thanks';
   $to = 'others@email.com';
  $msg = 'SEND these to each email above thanks';



  foreach($email as $email)
  {
  $to = $email["to"];


   $subject = 'the subject';
   $message = '$msg';
   $headers = 'is this really? ';
   mail($to, $subject, $message, $headers);

   }

非常感谢您对我的解决方案的影响

1 个答案:

答案 0 :(得分:0)

尝试拆分电子邮件字符串,并为每封电子邮件执行发送邮件的代码

<?php

$emails = 'email1@example.com,email2@example.com';
$emailsSplitted = explode(',', $emails);

foreach ($emailsSplitted as $email) {
    // ...
    // use here the variable $email to send the message
}