How can I add HTML formatting to "PHP-based quick writing"?

I have developed a contest page for the client, and they want the client to receive more than just text via email. The tutorial that I used provided plain text in the message "Send message body". I need to add html to thank the client for input by entering images on this letter.

The code:

//send the welcome letter
function send_email($info){

    //format each email
    $body = format_email($info,'html');
    $body_plain_txt = format_email($info,'txt');

    //setup the mailer
    $transport = Swift_MailTransport::newInstance();
    $mailer = Swift_Mailer::newInstance($transport);
    $message = Swift_Message::newInstance();
    $message ->setSubject('Thanks for entering the competition');
    $message ->setFrom(array('info@examplemail.com' => 'FromEmailExample'));
    $message ->setTo(array($info['email'] => $info['name']));

    $message ->setBody('Thanks for entering the competition, we will be in touch if you are a lucky winner.');

    $result = $mailer->send($message);

    return $result;

}

This functions.php file works, and the client receives the email in the order, I just need to change

("Thank you for participating in the contest, we will be in touch if you are lucky with a winner. ')

instead of HTML ...

Please attach me an example of how I can integrate HTML into this function.

+3
3

'text/html' setBody (ref):

->setBody($this->renderView('YouBundleName:Default:email.html.twig'), 'text/html');
+5
$message = Swift_Message::newInstance();
$message->setContentType('text=html');
+1

Will the same text remain or should it be somehow designed? Editing your letters in html requires built-in CSS styles, for example:

('<p style="font-size:1.2em; color:#f0f0f0;">Thanks for entering the competition, we will be in touch if you are a lucky winner.</p>')

if you need a table just added:

('<table style="font-size:1.2em; color:#f0f0f0;"><tr><td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td></tr></table>')

or make it simpler

$message_body'
<table style="font-size:1.2em; color:#f0f0f0;">
<tr>
<td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td>
</tr>
</table>
';

$message ->setBody($message_body);

I know that when I need to send html letters, I need to set the content type to html, which, I believe, you did in the next line

$body = format_email($info,'html');

Hope this is what you were looking for. if not let me know

0
source

Source: https://habr.com/ru/post/1743380/


All Articles