Page 1 of 1

stray characters in my html emails

Posted: Sat Aug 04, 2007 10:10 pm
by krraleigh
I have created an HTML email using PHP Mail
It works great except every 5 or so emails a stray character is
injected into my email
!
I have no idea where this character is coming from but I will show a fragment of my code:

Code: Select all

$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org'>Home</a><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/'>Bethel</a><br/>";	
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.singles.ag.org/'>AG-Singles</a><br/>";	
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/Sermons.htm'>Sermons</a><br/>";
And this is the code from the body of my email message. NOTE the non breaking space
on the third line and the very last character.

Code: Select all

<p><span style=A:link {color:#FFFFFF; text-decoration: none; font-size: 9px; line-height: 1.2em; font-family:Verdana, Arial;}'><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org'>Home</a><br/>&nbs!
 p;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/'>Bethel</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a
Does anyone have any experience with HTML email sends?
Did you use special formating? The reason I ask is I find lots of code in my personal HTML emails that I receive from verious groups and organizations that I belong to. I am wondering if I am supposed to include these types of characters in my emails?

Your insight would be appreciated
Thank You
Kevin

NOTE: As it stands I can send email I just have a a few stray chars in my navigation, but if this stray char pops up in the html table formating it could skew the entire message.

This is way over the top but if you were interested in what my html email looks like in its entirety:

Code: Select all

<?php require_once('sessionMan_cookiesCheck_DBconn.php'); ?>

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "admin@mysite.org";
$mail->FromName = "user";
$mail->Host     = "relay-hosting.securesever.net"; // SMTP servers
$mail->Port     = 3535;
//$mail->Mailer   = "smtp";

$query  = ('SELECT fName, email, accessLevel FROM user where accessLevel="user"')or die(mysql_error());
$result = MYSQL_QUERY($query);

while ($row = mysql_fetch_array ($result))
{
    // HTML body
	
	$myBody ="<html>";
	$myBody .="<head>";
	$myBody .="</head>";
	$myBody .="<body bgcolor='#FFFFFF' LINK='#FFFFFF' VLINK='#FFFFFF' ALINK='#FFFFFF'>";
	$myBody .="<table width='620' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#092F5E'>";
	$myBody .="<tr>";
	$myBody .="<td height='115' colspan='3' valign='top'>";	
	$myBody .="<img alt='banner' src='cid:my-attach1'/>"; //banner.jpeg--banner image here
	$myBody .="</td>";
	$myBody .="</tr>";
	$myBody .="<tr>";
	$myBody .="<td valign='top' width='18%' height='150'>";
	$myBody .="<p>&nbsp;</p>";
	$myBody .="<div align='center' style='color:#FFFFFF; font-family:Verdana; line-height: 1.3em; font-size: 11px;'>";
	$myBody .="<p>WEDNESDAYS<br />";
	$myBody .="Keys Chapel<br />";
	$myBody .="<strong>7:15PM<//strong><br />";
	$myBody .="<em>(before service)</em> <br />";
	$myBody .="The   Connection<br />";
	$myBody .="6:45PM<br />";
	$myBody .="In  Room 123 <br />";
	$myBody .="Next Door";
	$myBody .="</p>";
	$myBody .="<p>SUNDAYS<br />";
	$myBody .=""On Course"<br />";
	$myBody .="Crystal   Room<br />";
	$myBody .="<strong>9:15AM</strong></p>";
	$myBody .="<p><a href='http://www.bethel.org/WNLBulletin.pdf'>Events<br />";
	$myBody .="Bulletin<br /></a>";
	$myBody .="</p>";
	$myBody .="<p>PASTOR<br />";
	$myBody .="Art Gorman</p>";
	$myBody .="<p>PHONE<br />";
	$myBody .="(408) 246-6790<br />";
	$myBody .="x247</p><br/><br/><br/><br/><br/><br/>";
	$myBody .="</div>";
	$myBody .="</td>";
	$myBody .="<td width='62%' valign='top' bgcolor='#FFFFFF'>";
	$myBody .="<table width='100%' align='center' cellpadding='20'>";
	$myBody .="<tr>";
	$myBody .="<td width='81%' align='left' valign='top'>";
	$myBody .="<p>&nbsp;</p>Make my joy complete by being of the same mind, maintaining the same love,   united in spirit, intent on one purpose.";
	$myBody .="<div align='right'><strong>Philippians 2:2</strong></div> </td>";
	$myBody .="<td width='19%' align='left' valign='top'>";
	$myBody .="<img alt='PA and Wife' src='cid:my-attach'/> "; //PaAndWife.jpeg--image of pastor art and kay
	$myBody .="</td>";
	$myBody .="</tr>";
	$myBody .="<tr>";
	$myBody .="<td colspan='2' align='left' valign='top'>";	
	$myName = $row['fName'];
	$myName = trim("$myName", "'");
	$myBody .="<p><strong>Hi: $myName </strong></p>";// insert user name here
	$myBody .="<p>".$_POST['elm1']."</p>";
	$myBody .="</td>";
	$myBody .="</tr>";
	$myBody .="<tr>";
	$myBody .="<td colspan='2' align='left' valign='top'>";
	$myBody .="If you wish to be removed from 1Purpose mailing list please";
	$myBody .="<a href='mailto:1padmin@1purpose-bethel.org' style='color:blue;'> click here</a>! Place remove me in the subject list. Then place your name and email address in the body of the document<br/><div align='right'>Thank You!</div>"; 
	$myBody .="</td>";
	$myBody .="</tr>";
	$myBody .="</table>";
	$myBody .="</td>";
	$myBody .="<td valign='top' width='20%'>";
	$myBody .="<p><span style=A:link {color:#FFFFFF; text-decoration: none; font-size: 9px; line-height: 1.2em; font-family:Verdana, Arial;}'><br/><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org'>Home</a><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/'>Bethel</a><br/>";	
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.singles.ag.org/'>AG-Singles</a><br/>";	
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/Sermons.htm'>Sermons</a><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/newsBriefs.php'>News</a><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/personalGrowth.html'>Growth</a> <br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/ministries.html'>Ministries</a><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://bible.oneplace.com/'>Bible Tools</a><br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/sportsFitness.php'>Fitness-Sports</a>";
	$myBody .="<br/>";
	$myBody .="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/images/phpSlideshow/phpslideshow.php'>Slideshows</a><br />";
	$myBody .="</span></p>";
	$myBody .="</td>";
	$myBody .="</tr>";
	$myBody .="</table>";
	$myBody .="</body>";
	$myBody .="</html>";

    // Plain text body (for mail clients that cannot read HTML)
    $text_body  = $_POST['plainTextBody'];

    $mail->Body    = $myBody;
    $mail->AltBody = $text_body;
    $mail->AddAddress(trim($row["email"], "'"), trim($row["fName"], "'"));
	$mail->AddEmbeddedImage("banner.jpg", "my-attach1", "banner.jpg");
	$mail->AddEmbeddedImage("PaAndWife.jpeg", "my-attach", "PaAndWife.jpeg");
	

    //$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

    if(!$mail->Send())
        echo "There has been a mail error sending to " . $row["email"] . "<br>";

    // Clear all addresses and attachments for next loop
    $mail->ClearAddresses();
    $mail->ClearAttachments();
}
?>
	<script type="text/javascript">
	alert("Your messages have been sent!\n\nMay the lord continue to bless this ministry!\n\n");
	window.location = "../connect.php";
	</script>

<?php
	echo "<h4>The mail has been sent! May the lord continue to bless this ministry!</h4>";
?>

Posted: Sat Aug 04, 2007 10:14 pm
by RobertGonzalez
Without seeing the content of the mail that is throwing the stray char it is hard to guess what is causing it. Where in the message do these characters appear?

Posted: Sat Aug 04, 2007 10:37 pm
by krraleigh
I found the problem. It seems that I have one line of code on line 52 that is one very long string.
This string ends with a " ! " But I don't know what to do about it??
I tried using the newline char " \n " to brake up the lines of code but it won't work with html email.
Any ideas?

line 52

Code: Select all

<html><head></head><body bgcolor='#FFFFFF' LINK='#FFFFFF' VLINK='#FFFFFF' ALINK='#FFFFFF'><table width='620' border='0' align='center' cellpadding='0' cellspacing='0' bgcolor='#092F5E'><tr><td height='115' colspan='3' valign='top'><img alt='banner' src='cid:my-attach1'/></td></tr><tr><td valign='top' width='18%' height='150'><p>&nbsp;</p><div align='center' style='color:#FFFFFF; font-family:Verdana; line-height: 1.3em; font-size: 11px;'><p>WEDNESDAYS<br />Keys Chapel<br /><strong>7:15PM<//strong><br /><em>(before service)</em> <br />The   Connection<br />6:45PM<br />In  Room 123 <br />Next Door</p><p>SUNDAYS<br />"On Course"<br />Crystal   Room<br /><strong>9:15AM</strong></p><p><a href='http://www.bethel.org/WNLBulletin.pdf'>Events<br />Bulletin<br /></a></p><p>PASTOR<br />Art Gorman</p><p>PHONE<br />(408) 246-6790<br />x247</p><br/><br/><br/><br/><br/><br/></div></td><td width='62%' valign='top' bgcolor='#FFFFFF'><table width='100%' align='center' cellpadding='20'><tr><td width='81%' align='left' valign='top'><p>&nbsp;</p>Make my joy complete by being of the same mind, maintaining the same love,   united in spirit, intent on one purpose.<div align='right'><strong>Philippians 2:2</strong></div> </td><td width='19%' align='left' valign='top'><img alt='PA and Wife' src='cid:my-attach'/> </td></tr><tr><td colspan='2' align='left' valign='top'><p><strong>Hi: Bob </strong></p><p><p>This is your message!</p><p><strong>Pastor Art Gorman</strong></p></p></td></tr><tr><td colspan='2' align='left' valign='top'>If you wish to be removed from 1Purpose mailing list please<a href='mailto:1padmin@1purpose-bethel.org' style='color:blue;'> click here</a>! Place remove me in the subject list. Then place your name and email address in the body of the document<br/><div align='right'>Thank You!</div></td></tr></table></td><td valign='top' width='20%'><p><span style=A:link {color:#FFFFFF; text-decoration: none; font-size: 9px; line-height: 1.2em; font-family:Verdana, Arial;}'><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp!
end line 52 See the exclamation!
begin line 53

Code: Select all

;&nbsp;<
begin line 54

Code: Select all

a href='http://www.1purpose-bethel.org'>Home</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/'>Bethel</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.singles.ag.org/'>AG-Singles</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.bethel.org/Sermons.htm'>Sermons</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/newsBriefs.php'>News</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/personalGrowth.html'>Growth</a> <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/ministries.html'>Ministries</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://bible.oneplace.com/'>Bible Tools</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/sportsFitness.php'>Fitness-Sports</a><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.1purpose-bethel.org/images/phpSlideshow/phpslideshow.php'>Slideshows</a><br /></span></p></td></tr></table></body></html>
insight appreciated
thank you
Kevin

Posted: Sat Aug 04, 2007 10:40 pm
by RobertGonzalez
I think the line length may be causing you problems. How about you ditch all the non breaking spaces and see what happens. Or perhaps, just delete the '!'. Or is it necessary for the message you are sending?

Posted: Sat Aug 04, 2007 10:47 pm
by krraleigh
I am sure it is the line length, but this char is being injected into the end of the line.
I don't inject it the server or my mail program is injecting it at the end of the line.

I also just found out that where ever the line is terminated and I can change where it terminates
by adding and subtracting code that it still injects at the end of line 52.

any ideas
Kevin

Posted: Sat Aug 04, 2007 11:45 pm
by Benjamin
This could be a charset issue. Also, email line lengths are limited to something like 72 characters. You may want to research that and see what the actual line length limit is because that is the first number that came to my mind.

Posted: Sun Aug 05, 2007 1:33 am
by krraleigh
any ideas on how I might search this subject?
I tried searching on the injected character " ! " and string length
I tried max length for an email string, and a few other things, but
came up with nothing.

Not really sure how to start the research end of this.
Also of interest, I took the entire HTML string and did
a char count and came up with 3200 give or take.

So my thinking is there is a maximum number of chars
allowed in the string before a forced break happens.
I was able to partially validate this idea by adding and
subtract chars from the HTML, which moved the offending
char forward and back. :roll:
So how do you send out large emails without this break
messing with your HTML? :?

Is there a place on the web where they talk about the inns
and outs of sending email?

Your insight is greatly appreciated
Thank You
Kevin

Posted: Sun Aug 05, 2007 2:12 am
by Benjamin
d11wtq is the mail expert around here. You may just want use his swiftmailer