PDA

View Full Version : Battle of the hosts?


student101
09-18-2008, 07:00 AM
Using this HTML email setup;
I get the same results from 2 out of 3 hosts
The one host sends it as it should be, the other two give me HTML tags galore.
Is it my code?
<?php
function send_email($to='', $from='', $subject='', $html_content='', $text_content='', $headers='') {
# Setup mime boundary
$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "Reply-To: no-reply@example.com\r\n";
$body = "This is a multi-part message in mime format.\n\n";
# Add in plain text version
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $text_content;
$body.= "\n\n";
# Add in HTML version
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $html_content;
$body.= "\n\n";
# Attachments would go here
# But this whole email thing should be turned into a class to more logically handle attachments,
# this function is fine for just dealing with html and text content.
# End email
$body.= "--$mime_boundary--\n"; # <-- Notice trailing --, required to close email body for mime's
# Finish off headers
$headers .= "From: $from\r\n";
$headers .= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n";
$headers .= 'Date: '.date('n/d/Y g:i A')."\r\n";
# Mail it out
return mail($to, $subject, $body, $headers);
}
?>
<?php
$username = "info@example.com";
$emname= "Name";
$random_chars = substr(str_shuffle('abcdefghjkmnpqrstuvwxyz2345678 9'), 0, 8);
$body = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title></title>
<link href='http://www.example.com/css/admin.css' rel='stylesheet' type='text/css' />
</head>
<body>
<table width='762' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td>&nbsp;</td>
<td><div align='center'><img src='http://www.example.com/img/logo.jpg' alt='Image' /></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align='center'></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align='left'>
<p>Dear $emname,</p>
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Your password is <font color='#5E7D8F'><em><strong>$random_chars</strong></em></font></p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><hr/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Please click this link to continue; <a href='http://www.example.com/'>Login</a></p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><hr/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>&nbsp;</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Regards,</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Webmaster</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><hr/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align='right'>
<p><em><a href='http://www.example.com/'>example</a></em></p>
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>";
//$text_body ="";
$text_body= "Dear $emname,<br><br>Your new password is $random_chars<br>";
$text_body.= "<br>---------------------<br>";
$text_body.= "Please click the link to continue; <a href='http://www.example.com/'>Login</a>";
$text_body.= "<br>---------------------<br>";
$text_body.= "<br><br>Regards,<br>Webmaster";
$text_body.= "<br>Text version created by <a href='http://www.example.com/'>example</a>";
?>
<?php
send_email($to=$username, $from='no-reply@example.com', $subject='Forgotten Password', $html_content=$body, $text_content=$text_body, $headers='From:$from \r\n');
header ("Location:thank_you.php");
?>

student101
09-18-2008, 08:46 AM
I had a chat with 1 of the 2 hosts that state it's not the code as it sends the email but that doesn't solve my question.
Why do I not get the desired result and only get HTML tags galore?

davidj
09-18-2008, 09:27 AM
so all the email hosts work regarding sending the email but 2 of them send mail with visible HTML tags?

student101
09-18-2008, 09:32 AM
Yes, (attempting to rather use swiftmailer for these "dumb" hosts) it works fine on another host and my own pc.

Ridiculous.

davidj
09-18-2008, 05:10 PM
need to see what your receiving as HTML

student101
09-18-2008, 05:36 PM
Content-Type: multipart/alternative; boundary="Multipart_Boundary_x265482aa97c5a6d077e57064e86f22 bax" Content-Transfer-Encoding: 7bit Reply-To: no-reply@example.com
From: no-reply@example.com
X-Sender-IP: 67.15.70.75 Date: 9/18/2008 10:26 AM
This is a multi-part message in mime format.
--Multipart_Boundary_x265482aa97c5a6d077e57064e86f22 bax
Content-Type: text/plain; charset="charset=us-ascii"
Content-Transfer-Encoding: 7bit
Dear Name,<br><br>Your new password is vtk2p47n<br><br>---------------------<br>Please click the link to continue; <a href='http://www.example.com/'>Login</a><br>---------------------<br><br><br>Regards,<br>Webmaster<br>Text version created by <a href='http://www.example.com/'>Example</a>
--Multipart_Boundary_x265482aa97c5a6d077e57064e86f22 bax
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd (http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> <title></title> <link href='http://www.example.com/css/admin.css' rel='stylesheet' type='text/css' /> </head>
<body>
<table width='762' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td>&nbsp;</td>
<td><div align='center'><img src='http://www.example.com/img/logo.jpg' alt='Logo' /></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align='center'></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align='left'>
<p>Dear Name,</p>
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Your password is <font color='#5E7D8F'><em><strong>vtk2p47n</strong></em></font></p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><hr/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Please click this link to continue; <a href='http://www.example.com/'>Login</a></p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><hr/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>&nbsp;</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Regards,</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><p>Webmaster</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><hr/></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align='right'>
<p><em>HTML version created by <a href='http://www.example.com/'>Example</a></em></p>
</div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>
--Multipart_Boundary_x265482aa97c5a6d077e57064e86f22 bax--

student101
09-19-2008, 07:06 AM
I think it's cause they use Sendmail and not Qmail, really not sure.
From the host that works they use Qmail.
From the host that DON't works they use Sendmail and some other odd thingy's

Cheers

davidj
09-19-2008, 02:43 PM
thats logical

have you enquired officialy

student101
09-19-2008, 05:42 PM
Yes and the one host suggested that it's my code and that I would have to pay for their support team to test it.
My response was simple and obvious - "If you can prove that it's my code then I'll pay, otherwise you pay me what I would've paid you."

They said sure, and have not bothered to come back - which automatically implies that my code is fine and that they don't want to pay.

The other host suggested that I use SwiftMail - cause it supports their mail servers. I tested this and the result was true.

The fact that the first host could not or would not suggest that is probably due to LACK OF knowledge - Needles to say I should move to the host that supports that has knowledge.

Cheers