Laravel邮件发送配置问题

我的需求是,针对不同的业务或者群体,使用的发件箱不一样,如果使用laravel中的mail发送,发件箱这个不知道咋改,求助

Mail::send('mall.suggest.mail', $data, function ($message) {
                        $message->from('a@163.com', '发送人A');
                        $message->sender('a@163.com', '发送人A');
                        $message->to('receiver@qq.com', 'receiver@qq.com');
                        $message->subject("邮件标题");

                    });

其中mail.php中默认配置了a@163.com,但我现在想用b@163.com发送,有么有什么办法可以实现的?

阅读 3.2k
2 个回答

laravel没用过,不过swiftMailer可以这样搞:

$transport = Swift_SmtpTransport::newInstance($send_host, 25)
    ->setUsername($email_config['email'])
    ->setPassword($email_config['password']);
$mailer = new Mailer();
$mailer->setTransport($transport);
//Priority value, should be an integer in range: 1..5, where 1 is the highest priority and 5 is the lowest.
$priority = $email['isurgent'] == 2 ? 1 : 3;
$message = (new Message())
    ->setFrom([$email['send_mail'] => $email['send_name']])
    ->setTo(explode(';', $email['receive_mail']))
    ->setSubject($email['title'])
    ->setHtmlBody($email['content'])
    ->setPriority($priority);
$email['ccperson'] ? $message->setCc(explode(';', $email['ccperson'])) : '';
$email['bccperson'] ? $message->setBcc(explode(';', $email['bccperson'])) : '';
$email['isreturn'] ? $message->setReadReceiptTo($email['send_mail']) : '';
$attachment = json_decode($email['attachment'] ?: '[]', true);
$base_path = getcwd() . '/';
foreach ($attachment as $v) {
    if (file_exists($base_path . $v['path'])) {
        $message->attach($base_path . $v['path'], ['fileName' => $v['name'], 'contentType' => $v['type']]);
    }
}
$result = $mailer->send($message);

设置下transport 。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进