简体   繁体   中英

how we can send email with multiple email account as sender

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM