[英]Send a mail to formatted email address using Google Apps Engine and PHP
[英]Send a mail to formatted email address using Google Apps Engine and PHP
require_once 'google/appengine/api/mail/Message.php';
use google\appengine\api\mail\Message;
// ...
$message_body = "...";
$mail_options = [
"sender" => "admin@example.com",
"to" => "user@example.com",
"subject" => "Your example.com account has been activated.",
"textBody" => $message_body
];
try {
$message = new Message($mail_options);
$message->send();
} catch (InvalidArgumentException $e) {
// ...
}
我使用上面的代码从Google Apps Engine发送电子邮件(用于PHP托管),并且它正在成功运行。
但我需要发送邮件发送到格式化的电子邮件地址,如联系人姓名<user@example.com>
我尝试使用以下代码,但它无法正常工作,我的exception 'InvalidArgumentException' with message 'Invalid 'to' recipient: <user@example.com>'
$mail_options = [
"sender" => "admin@example.com",
"to" => "Contact Name <user@example.com>",
"subject" => "Your example.com account has been activated.",
"textBody" => $message_body
];
和
$mail_options = [
"sender" => "admin@example.com",
"to" => "Contact Name <user@example.com>",
"subject" => "Your example.com account has been activated.",
"textBody" => $message_body
];
可能吗?
你有没有错误( Invalid sender address
)是与邮件( 发件人 admin@example.com
在你的示例代码),而不是来解决。 邮件服务文档包含以下发件人地址的安全限制:
出于安全考虑,邮件的发件人地址必须是应用程序管理员的电子邮件地址或应用程序的任何有效电子邮件接收地址(请参阅接收邮件)。 如果用户的帐户是Gmail帐户或位于Google Apps管理的域中,则发件人也可以是登录当前用户的Google帐户电子邮件地址。
您可以在App Engine控制台中管理应用程序的管理员。
如果您先看一下,那么您的示例可能会起作用(使用Java API肯定是可行的,但我不熟悉PHP版本)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.