Pergunta

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) {
    // ...
}

I have used the above code for sending email from Google Apps Engine(for PHP Hosting)and its is working successfully.

But i need a mail send to formatted email address like Contact Name

I have try with the following code but it is not working and i got exception

'InvalidArgumentException' with message 'Invalid 'to' recipient: '

$mail_options = [
    "sender" => "admin@example.com",
    "to" => "Contact Name <user@example.com>",
    "subject" => "Your example.com account has been activated.",
    "textBody" => $message_body
];

and

$mail_options = [
    "sender" => "admin@example.com",
    "to" => "Contact Name <user@example.com>",
    "subject" => "Your example.com account has been activated.",
    "textBody" => $message_body
];

Is it possible?

Foi útil?

Solução

Doesn't look like it. Your second example with the actual brackets would normally be perfectly valid in a To header.

I managed to find the documentation for the mail\Message class (the link in their PHP API is wrong) but it isn't very good; Generated automatically by phpDocumentor, so all you really get is an overview of the functions/arguments and any comments the developers were kind enough to put in (not much in this case).

https://developers.google.com/appengine/docs/php/refdocs/files/api.mail.Message

Going by the docs, all the recipient functions take an 'email' as the argument. Considering your tests produced invalid argument responses, it appears that literally does means purely an email address.

A work-around may have been to use the clearTo method to clear recipients, then add a To header manually with addHeader. Unfortunately they heavily limit the headers you can add like this, and To isn't one of them. Probably to stop you bypassing whatever checks they are doing on the addresses you pass via the proper methods.

You'll probably have to try and contact AppEngine support for any further information. As I mentioned above, the docs aren't very good and don't make it clear at all what is and isn't valid.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top