Sending email using Swift mailer in Yii2 sent wrong email contents

I am using Swift mailer to send email from my Yii2 based web applications. But it can’t read/receive in MS Outlook correctly.

Please see the email body bellow which I received using MS Outlook 2010 -




--_=_swift_v4_1430198154_31f7ff2886dc0fb65796db153d9434096acbae54_=_

Content-Type: text/plain; charset=UTF-8

Content-Transfer-Encoding: quoted-printable


Dear Admin,=20

User john has been si= gned up

successfully.


Thanks,

The App Tea=

m


This message was sent to john@example.com. If y= ou don't want

to receive future emails from ABC, please unsubs= cribe.




--_=_swift_v4_1430198154_31f7ff2886dc0fb65796db153d9434096acbae54_=_

Content-Type: text/html; charset=UTF-8

Content-Transfer-Encoding: quoted-printable


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.=

org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns=3D"http://www.w3.org=

/1999/xhtml">

<head>

<meta http-equiv=3D"Content-Type" con= tent=3D"text/html;

charset=3DUTF-8" />

<title></title>

<=

/head>

<body>

	Dear Admin, <br>

<p>User John has been signed up successfully.</p>


<=

p>Thanks,</p>

<p>The ABC Team</p>


<br><br><br> =


=09

<p style=3D'color: #B6B6B6'>

	This message was sent to =

john@example.com. If you don't want to receive future emai= ls

from ABC, please <a href=3D'#'>unsubscribe</a>.

</p> =





</body>

</html>




--_=_swift_v4_1430198154_31f7ff2886dc0fb65796db153d9434096acbae54_=_--



I am using following configuration for encoding-


 'messageConfig' => [

 	'charset' => 'UTF-8', ],



And sending using-


Yii::$app->mailer->compose('mailview', ['name' => $name]) 

     		->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->name . ' App'])

         	->setTo($to)

     		->setSubject($subject)

     		->send();

What am I missing?

Please provide info what transport service are you using for sending - PHP mail() function, SMTP server or IMAP?

Are you sending within your intranet or to some external server?

How is your network configured - does firewall allow outgoing requests on given port, are you using proxy etc…?

Mail body you provided is actually irrelevant information.

Tip: you can setup local mail server with either IIS server or hMailServer, if you need solid testing environment for emails.

Thanks.

I am using SMTP to send email from my Yii 2 based web application. I can receive and read email without any problem using other email services i.e Gmail, Yahoo but if I want to receive via IMAP (using MS Outlook 2010) then the email appear as unreadable.

I have added mail configuration code block below-


'mailer' => [

	'class' => 'yii\swiftmailer\Mailer',

	'viewPath' => '@common/mail',

	'useFileTransport' => false,


	'transport' => [

			'class' => 'Swift_SmtpTransport',

			'host' => 'localhost',

			'username' => 'mailer@example.com', // SMTP username

			'password' => '********',

			'port' => '25',

	],

	

	'messageConfig' => [

		'charset' => 'UTF-8',

	],

],