dtuzjzs3853 2019-05-20 09:44
浏览 235

我们如何发送电子邮件与多个电子邮件帐户作为发件人

I want to send email with some accounts to some targets.But when use this code all emails are delivered to first sender account only.

from() just change name of sender in message and it could not change sender account

while(true)
{
$config = array(
            'driver' => 'smtp',
            'host' => $smtp,
            'from' => array('address' => $senders[$p], 'name' => 
  $senderName),
            'username' => $senders[$p],
            'password' => $senderpasses[$p],
            'port' => '587',
            'encryption' => 'tls'
        );        
   Config::set('mail', $config);
            $data = [
                'target' => $email[$m],
                'text' => $text,
                'title' => $title,
                'sender' => $senders[$p],
                'senderName' => $senderName
            ];

            try {
                Mail::send('emails.mail', ['data' => $data], function 
   ($message) use ($data) {
                    $message->from($data['sender'], $data['senderName']);
                    $message->to($data['target'])- 
   >subject($data['titl']);
                });
            } catch (\Exception $e) {
                echo $e->getMessage();
            }
           $m++;
           $p++;
        if ($p >= count($senders)) {
            $p = 0;
        }
        if ($m >= count($email)) {
             return ($m);
        }
    }

it send email just with first sender and other users are not used.

  • 写回答

1条回答 默认 最新

  • douyuan4825 2019-05-20 09:51
    关注

    Emails are, by definition, sent from a single sender to multiple addresses, so it is not possible to achieve what you are asking for.

    You have to send the mail multiple times, one for each sender. May I ask you what is the purpose of this scenario?

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)