Yii Framework Forum: How to send mails without html-tags - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to send mails without html-tags [solved]

#1 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 400
  • Joined: 20-April 17
  • Location:Hannover

Posted 29 December 2017 - 02:15 PM

Hi guys,
following code will send mails. Attachements will be send,too.
I noticed, that message in Mail will be send with html-tags like this:

Message-ID: <4cc0edba23a9701ef8a266dc016d772b@localhost>
Date: Fri, 29 Dec 2017 20:15:25 +0100
Subject: Punkertreffen
From: abc@gmail.com
To: tklustig.thomas@gmail.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="_=_swift_1514574925_c56cb584f26c9f71b3d2747999f9dae7_=_"
--_=_swift_1514574925_c56cb584f26c9f71b3d2747999f9dae7_=_[
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<p>Laut taZ findet am heutigen Samstag ein <span style=3D"font-size:18px"><=
span style=3D"font-family:Comic Sans MS,cursive">Punktertreffen </span></sp=
an>in Hannover statt,die sogenannten Chaostage.</p>
<p>Punker aus ganz Europa treffen sich zu einem Sit-In</p>
--_=_swift_1514574925_c56cb584f26c9f71b3d2747999f9dae7_=_
Content-Type: image/jpeg; name=newspaper.jpg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=newspaper.jpg
.
.


That's nonsense, of course. Any ideas, how to send mail correctly?
if ($anhangszaehler >= 1) {
$SendObject = Yii::$app->mailer->compose()
->setFrom($model_eingang->mail_adresse_absender)
->setTo($model->mail_antwortadresse)
->setSubject($model->betreff)
->setTextBody($model->bodytext); //this will be send with html-tags
	foreach ($anhang as $file) {
		$SendObject->attach($folder_write . $file);
	}
$SendObject->send();
$session->addFlash("info", "Die Mail wurde mit Anhängen versandt.Bitte überprüfen sie ihren Maileingang");
} 

0

#2 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,546
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 29 December 2017 - 03:21 PM

by looking at the headers I assume the content-type is set properly

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


its is very likely your bodytext contains markup run it through strip_tags to remove the tags


->setTextBody(strip_tags($model->bodytext));

1

#3 User is offline   tklustig 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 400
  • Joined: 20-April 17
  • Location:Hannover

Posted 29 December 2017 - 05:00 PM

View Postalrazi, on 29 December 2017 - 03:21 PM, said:

by looking at the headers I assume the content-type is set properly

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


its is very likely your bodytext contains markup run it through strip_tags to remove the tags


->setTextBody(strip_tags($model->bodytext));



Great!
Ur single code line will send mail as intented. I didn't know this php function. Now, i know it!
Thx a lot for this information.
This thread can be closed as succesfully solved



0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users