Mandrill PHP 图书馆 - 来自田野

Mandrill PHP library - FROM field

如何为 PHP Mandrill 库设置合适的 FROM 字段?

在Java中,我可以使用:

from = "Some Description <noreply@domain.com>";

如果我在 PHP 中尝试相同的操作,我会得到一个错误:

Validation error: {"message":{"from_email":"The username portion of the email address is invalid (the portion before the @: Some Description

只有这样的发件人的电子邮件才能通过:

$from = "noreply@domain.com";

以防万一,这是我发送电子邮件的方式:

$from = "Some Description <noreply@domain.com>";
$message = array("subject" => $aSubject, "from_email" => $from, "html" => $aBody, "to" => $to);

$response = $mandrill->messages->send($message, $async = false, $ip_pool = null, $send_at = null);

如果你阅读文档 https://mandrillapp.com/api/docs/messages.html 它有两个请求参数 from_emailfrom_name 当我们通过

$from = "Name <email>",

它不被 mandrill 接受,因此它会抛出错误,要传递名称,您需要传递具有名称值的 from_name。