Reputation: 362
I am using a php
application on google application engine
to send emails
but whenever I check the actual email received it does not have any formatting or styling even though i added some html
in there . I get back the tags and all. I would like to add my own html styling to the email. The code I am using is:
require_once 'google/appengine/api/mail/Message.php';
use google\appengine\api\mail\Message;
$mail_options = [
"sender" => '[email protected]',
"to" => $toaddr,
"subject" => $subj,
"textBody" => $msg,
];
try
{
$message = new Message($mail_options);
$message->send();
echo '<h1>success</h1>';
}
catch (InvalidArgumentException $e)
{
echo $e;
}
Upvotes: 0
Views: 1257
Reputation: 8221
According to the documentation there is an option field htmlBody so you can add to it to your code
$mail_options = [
"sender" => '[email protected]',
"to" => $toaddr,
"subject" => $subj,
"textBody" => $msg,
"htmlBody" => $html_formatted_msg,
];
Note: I am using the Python runtime, which works in the same way, I haven't try this in php.
Upvotes: 3
Reputation: 456
Add the following before $message->send();
$message->isHTML(true);
And please refer this link, if it doen't work,
Upvotes: -1
Reputation: 940
Your mail function should be like this:
mail($to, $subject, $message, $headers);
With the $headers variable like this:
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
(The $headers variable should be defined before the mail function)
Hope it works.
Upvotes: 0