当且仅当以数组形式提交时,Swiftmailer 才拒绝有效的电子邮件地址
Swiftmailer rejecting valid email addresses if and only if submitted in array
我正在从 s2member 数据库中提取用户的 phone 号码,并附加通过电子邮件发送 SMS 文本所需的无线运营商域名 (Swift Mailer)。因此,为了创建电子邮件地址数组,我使用了以下内容(下面的函数 cellmap
只是将用户的无线运营商替换为要追加的正确域):
$matches = array();
if (is_array ($users) && count ($users) > 0) {
foreach ($users as $user) {
$user = new WP_User ($user->ID);
$matches[] = "'" . get_user_field("cell_no", $user->ID) . cellmap(get_user_field("cell_carrier",$user->ID)) . "'";
}
}
生成的数组如下所示,以 4 个匹配用户为例:
Array
(
[0] => '1234567891@vtext.com'
[1] => '3216549871@vtext.com'
[2] => '9876543211@vtext.com'
[3] => '6543219877@vtext.com'
)
然后我内爆创建一个字符串用作 Swift 邮件程序的 "To" 字段:
$cell_list = implode(", ", $matches);
结果如下(数字是编造的):
'1234567891@vtext.com', '3216549871@vtext.com', '9876543211@vtext.com', '6543219877@vtext.com'
现在我将其传递给 Swift Mailer,如下所示:
$outgoing_message = Swift_Message::newInstance('')
->setFrom(array('no-reply@mydomain.com' => 'Mydomain'))
->setTo($cell_list)
->setBody($message);
// Send the message
$result = $mailer->send($outgoing_message);
我收到此错误(忽略 phone 数字:它们是编造的,但实际上对应于正确的数字):
PHP Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given ['123456789@vtext.com', '987654321@vtext.com', '5555551212@vtext.com', '321654987@vtext.com'] does not comply with RFC 2822, 3.6.2.'
我可以通过 Swift Mailer 单独 成功发送这些电子邮件中的任何一封,但是当它们显示为数组时,我总是会收到上述错误。我尝试将 trim 应用于各个地址和整个结果字符串。数组的 print_r
不显示任何不可打印的字符。我尝试了 ->setTo($cell_list)
、->setTo(array('$cell_list'))
和任何其他可能有效的组合,但无济于事。我尝试用列表中的分号替换逗号,并删除每个地址周围的单引号。据我所知,电子邮件地址字符串的格式与 Swift Mailer 文档中显示的格式完全一致。对于我的生活,我无法弄清楚。
根据 Swiftmailer documentation,setTo
将单个电子邮件地址或一组电子邮件地址作为参数。
您的代码:
$cell_list = implode(", ", $matches);
$outgoing_message = Swift_Message::newInstance('')
->setFrom(array('no-reply@mydomain.com' => 'Mydomain'))
->setTo($cell_list)
->setBody($message);
使用 implode()
将所有电子邮件地址放在一个文本字符串中。
我建议不要内爆 $matches:
$outgoing_message = Swift_Message::newInstance('')
->setFrom(array('no-reply@mydomain.com' => 'Mydomain'))
->setTo($matches)
->setBody($message);
我正在从 s2member 数据库中提取用户的 phone 号码,并附加通过电子邮件发送 SMS 文本所需的无线运营商域名 (Swift Mailer)。因此,为了创建电子邮件地址数组,我使用了以下内容(下面的函数 cellmap
只是将用户的无线运营商替换为要追加的正确域):
$matches = array();
if (is_array ($users) && count ($users) > 0) {
foreach ($users as $user) {
$user = new WP_User ($user->ID);
$matches[] = "'" . get_user_field("cell_no", $user->ID) . cellmap(get_user_field("cell_carrier",$user->ID)) . "'";
}
}
生成的数组如下所示,以 4 个匹配用户为例:
Array
(
[0] => '1234567891@vtext.com'
[1] => '3216549871@vtext.com'
[2] => '9876543211@vtext.com'
[3] => '6543219877@vtext.com'
)
然后我内爆创建一个字符串用作 Swift 邮件程序的 "To" 字段:
$cell_list = implode(", ", $matches);
结果如下(数字是编造的):
'1234567891@vtext.com', '3216549871@vtext.com', '9876543211@vtext.com', '6543219877@vtext.com'
现在我将其传递给 Swift Mailer,如下所示:
$outgoing_message = Swift_Message::newInstance('')
->setFrom(array('no-reply@mydomain.com' => 'Mydomain'))
->setTo($cell_list)
->setBody($message);
// Send the message
$result = $mailer->send($outgoing_message);
我收到此错误(忽略 phone 数字:它们是编造的,但实际上对应于正确的数字):
PHP Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given ['123456789@vtext.com', '987654321@vtext.com', '5555551212@vtext.com', '321654987@vtext.com'] does not comply with RFC 2822, 3.6.2.'
我可以通过 Swift Mailer 单独 成功发送这些电子邮件中的任何一封,但是当它们显示为数组时,我总是会收到上述错误。我尝试将 trim 应用于各个地址和整个结果字符串。数组的 print_r
不显示任何不可打印的字符。我尝试了 ->setTo($cell_list)
、->setTo(array('$cell_list'))
和任何其他可能有效的组合,但无济于事。我尝试用列表中的分号替换逗号,并删除每个地址周围的单引号。据我所知,电子邮件地址字符串的格式与 Swift Mailer 文档中显示的格式完全一致。对于我的生活,我无法弄清楚。
根据 Swiftmailer documentation,setTo
将单个电子邮件地址或一组电子邮件地址作为参数。
您的代码:
$cell_list = implode(", ", $matches);
$outgoing_message = Swift_Message::newInstance('')
->setFrom(array('no-reply@mydomain.com' => 'Mydomain'))
->setTo($cell_list)
->setBody($message);
使用 implode()
将所有电子邮件地址放在一个文本字符串中。
我建议不要内爆 $matches:
$outgoing_message = Swift_Message::newInstance('')
->setFrom(array('no-reply@mydomain.com' => 'Mydomain'))
->setTo($matches)
->setBody($message);