Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mailer , sending html body problem.

Status
Not open for further replies.

dessie1981

Programmer
May 9, 2006
116
GB
Hi Everyone,

I need some expert advice again.

I have had to change from using mail() to php.mailer() as i want to use an exchange server on a perimiter Lan.

I am sending and recieving mails fine from my application however the html tags are being printed in the body of the mail now.

However when i use my old script using the mail() function it works fine and the html is being interpreted.

Here is my code.

Code:
//start mime section
$message = new Mail_mime();
$html = file_get_contents($filename);

$message->setHTMLBody($html);
$body = $message->get();

//start mailer section
$mail = new PHPMailer();
$mail->From     = "************";
$mail->FromName = "Tester";
$mail->Host     = "***.***.***.**";
$mail->Mailer   = "smtp";
$mail->AddAddress("***********");

$mail->Subject = "Order Confirmation";
$mail->Body    = $body;

if(!$mail->Send())
{
	echo '<p align = "center">Error sending mail</p>';
	
}
else 
{
	echo '<br>';
	echo '<hr>';
	echo '<p align ="center">Thank You</p>';
}

Any Help would be greatful

Regards
Dessie
 
you may be overcomplicating this. why are using mail_mime as well, for example?
Code:
$mail = new PHPMailer();
$mail->From     = "************";
$mail->FromName = "Tester";
$mail->Host     = "***.***.***.**";
$mail->Mailer   = "smtp";
$mail->AddAddress("***********");

$mail->Subject = "Order Confirmation";
$body = "Hello.  This is a test mail confirming your order";
$htmlbody = "<div style=\"color:red;\">$body</div>";

$mail->Body    = $htmlbody;
$mail->AltBody = $body

in your case i'd guess you would set
Code:
$mail->Body = file_get_contents($filename);
 
Hi Jpadie,

Thanks for the quick response but i made the changes you suggested and the mail is still printing out the tags.

Code:
//start mailer section
$mail = new PHPMailer();
$mail->From     = "**********";
$mail->FromName = "List manager";
$mail->Host     = "********";
$mail->Mailer   = "smtp";
$mail->AddAddress("**********");
$mail->Subject = "Order Confirmation";
$mail->Body = file_get_contents($filename);

if(!$mail->Send())
{
	echo '<p align = "center">Error sending mail</p>';
	
}
else 
{
	echo '<br>';
	echo '<hr>';
	echo '<p align ="center">Thank You</p>';
}



Regards
Dessie
 
This is the body of the message that i recieve.
It seems fine as when i copy it into a html file if works fine.

Code:
<html><head></head><body><p align = "left"><b>Order No : 1030</b></p><p align = "left"><b>Ordered By : testuser</b></p><p align = "left"><b>Organisation : test organisation</b></p><p align = "left"><b>Purchase Order No : 123</b></p><p align ="left"><b>Ordered on : 18 09 2006</b></p><blockquote>
	<blockquote>
      <blockquote>
		<p align="center">Please Note : This email indicates that we 
 have received your order. Please verify that the order 
		below is correct. Any queries can be directed to Des O Connor,
		<a href="mailto:**********</a> . </p>
	</blockquote>
	</blockquote>
</blockquote><br><br><center><table border=0>
<tr><td><center><b>PartNum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</b></center></td><td><center><b>Model</b></center></td><td><center><b>
Quantity</b></center></td><td><center><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;Price</b></center></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
<tr><td>PW337ET#ABU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>HP xw4300 - P4 3.2Ghz (2MB cache) 1GB (2x512) DDR2-533 160GB SATA (3.0Gb/s 7200rpm) no floppy combo drive NVIDIA Quadro NVS 285 128MB XP Pro 3 yrs onsite</td><td><center>9</center></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
€8955</td></tr>
<tr><td>PW337ET?PX849AT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>K/HP xw4300/P4 3000 512MB 80GB XPP/L1706</td><td><center>9</center></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
€8955</td></tr>
<tr><td><b>----------------</b></td><td></td></td><td><td>&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b>--------------------</b></td></tr><tr><td><b>Total</b></td><td></td>
</td><td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>€17910</b></td></tr><tr><td>
<b>Total incVAT</b></td><td></td></td><td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>
€21671.1</b></td></tr></body></html>

Regards
Dessie
 
try explicitly setting the application to use html
Code:
$mail->isHTML(true);

however i suspect that the real issue is that the html you have written is broken and that it's being brought in as translated html
Code:
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;cell content&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

if my hunch is right, use html_entity_decode() against the string.
 
Code:
$mail->isHTML(true);

did the trick alright, you must have to specify this when using the phpmailer class, did not see it in the documentation.

Thanks a million for your help again.

Regards
Dessie
 
strange. i though phpmailer defaulted to html. oh well - happy to help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top