Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an HTML email using Swift

I would like to send an auto-generated email with HTML body from my application using Swift.

Here is my current code:

$message = Swift_Message::newInstance()
                ->setFrom(array('[email protected]' => 'John Doe'))
                ->setTo('[email protected]')
                ->setSubject('some subject');

            $message->setBody($this->getPartial('global/mail_partial'));

            $this->getMailer()->send($message);

I had already tried to change the header Content-type of the email message using some specific Swift methods but it is not working.

like image 919
Rui Gonçalves Avatar asked Jun 24 '10 16:06

Rui Gonçalves


Video Answer


1 Answers

See:

Sending a HTML E-Mail (from SwiftMailer Docs)

You need to add this line to set html content-type:

$message->setContentType("text/html");

Alternatively, it can by done passing a second argument on the $message->setBody() method:

$message->setBody($this->getPartial('global/mail_partial'), 'text/html');.
like image 168
Sarfraz Avatar answered Oct 19 '22 09:10

Sarfraz