Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer AltBody is not working

PHPMailer Version 5.2.7

$mailerObject = new PHPMailer;
$mailerObject->CharSet = 'UTF-8';
$mailerObject->IsSMTP(); 
$mailerObject->Host = 'dsfdf.sdfsdf.com';
$mailerObject->SMTPAuth = TRUE;  
$mailerObject->Username = 'dfgdfg';
$mailerObject->Password = 'dfgdfgdfg'; 
$mailerObject->SMTPSecure = 'tls';
$mailerObject->WordWrap = 60;
$mailerObject->From = '[email protected]';
$mailerObject->FromName = 'test.de';
$mailerObject->AltBody = $bodyTextTemp;
$mailerObject->MsgHTML($bodyHtmlTemp);

I am sending an HTML-Mail and an Text-Mail. In Thunderbird in HTML-Mode HTML is correctly shown. In Text-Mode you cant see the Text-Content ($bodyTextTemp), but the HTML-Content ($bodyHtmlTemp) where all HTML-Tags were removed (looks very ugly...).

Looking to the Mail-source, I can see that the AltBody wasnt send.

Why PHPMail dont accept my AltBody?

like image 261
user1711384 Avatar asked Jul 03 '14 17:07

user1711384


1 Answers

Because msgHTML overwrites AltBody. If you want to set Body and AltBody yourself, just set them. msgHTML is a convenience function to do several things for you, but you don't need to use it. If you want to use it but also set AltBody, just set it after you call msgHTML.

like image 152
Synchro Avatar answered Oct 25 '22 18:10

Synchro