php - 如果在laravel中TO地址为空,如何发送邮件
问题描述
我正在尝试使用抄送地址而不是收件人地址发送邮件。
我的代码如下。
$mail_param['msg'] = "demo";
$mail_param['link'] = "xyz.com";
$email = '';
$name = "demo user";
$cc = 'abc@gmail.com';
Mail::send('view_template', $mail_param, function ($message) use ($email, $name, $cc) {
if ($cc != '') {
$message->to($email, $name)->bcc($cc)->subject('Test Mail');
} elseif ($email != '') {
$message->to($email, $name)->subject('Test Mail');
}
});
我正在尝试上面的代码并得到以下错误。
local.ERROR:给定 [] 邮箱中的地址不符合 RFC 2822, 3.6.2。
解决方案
您可以尝试使用数组参数。
$mail_param['msg'] = "demo";
$mail_param['link'] = "xyz.com";
$email = array();
$name = "demo user";
$cc = array('abc@gmail.com');
Mail::send('view_template', $mail_param, function ($message) use ($email, $name, $cc)
{
if (!empty($cc)) {
$message->to($email, $name)->bcc($cc)->subject('Test Mail');
} elseif (!empty($email)) {
$message->to($email, $name)->subject('Test Mail');
}
});
推荐阅读
- javascript - 在javascript中单击按钮时切换功能
- amazon-web-services - AWS 从 s3 中上传的 zip 文件创建层
- google-cloud-platform - 请确保您拥有此资源的 OWNER 角色访问权限
- javascript - 如何在 RGraph 中单击时获取标签索引
- go - “反映:字段索引超出范围”更新时出现恐慌
- javascript - 编写一个方法,接收一个句子字符串并返回一个表示其 Aba 翻译的新句子
- vue.js - Vue.js 如何从方法更改计算属性?
- python - PyTorch 的 DataParallel 只使用一个 GPU
- asp.net-core - 角色和组之间的 Azure 广告隔离
- sql - SQL 删除除顶部和底部之外的所有结果