Laravel邮件发送配置问题_其他语言_编程问答

Laravel邮件发送配置问题

来源:互联网  时间:2018/1/29 1:09:05

关于网友提出的“ Laravel邮件发送配置问题”问题疑问,本网通过在网上对“ Laravel邮件发送配置问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 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发送,有么有什么办法可以实现的?


解决方案1:

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 。

上一篇laravel 在文章列表中附带上前10条评论?
下一篇python3中的filetruncate是不是有本质改变?
明星图片
相关文章
《 Laravel邮件发送配置问题》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)