Please help?

I am getting the following error when executing a mass mailing script that contains HTML as the mail content:
Parse error: syntax error, unexpected '>' in ... on line 14
If I remove lines 14 to 27 (from <style> to </style>) I get the following error:
Parse error: syntax error, unexpected T_STRING in ... on line 14

Here is the code

<?php
include_once "connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM mail WHERE field_9='0' AND field_8='max' LIMIT 20");
$numRows = mysql_num_rows($sql); // Added for "End Campaign Check" at the bottom of this file(not shown on the video)
$mail_body = '';
while($row = mysql_fetch_array($sql)){
	$id = $row["id"];
	$email = $row["field_4"];
	$name = $row["field_5"];
	
	$mail_body = '
<html>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" bgcolor='#505050' >
<STYLE>
 .headerTop { background-color:#ffffff; border-top:0px solid #000000; border-bottom:1px solid #FFFFFF; text-align:center; }
 .adminText { font-size:10px; color:#ff7700; line-height:200%; font-family:verdana; text-decoration:none; }
 .headerBar { background-color:#e0e0e0; border-top:0px solid #333333; border-bottom:10px solid #FFFFFF; }
 .title { font-size:20px; font-weight:bold; color:#ff7700; font-family:arial; line-height:110%; }
 .subTitle { font-size:11px; font-weight:normal; color:#666666; font-style:italic; font-family:arial; }
 td { font-size:12px; color:#000000; line-height:150%; font-family:trebuchet ms; }
 .sideColumn { background-color:#e0e0e0; border-right:1px solid #505050; text-align:left; }
 .sideColumnText { font-size:11px; font-weight:normal; color:#999999; font-family:arial; line-height:150%; }
 .sideColumnTitle { font-size:15px; font-weight:bold; color:#333333; font-family:arial; line-height:150%; }
 .footerRow { background-color:#505050; border-top:10px solid #FFFFFF; }
 .footerText { font-size:10px; color:#ffffff; line-height:100%; font-family:verdana; }
 a { color:#FF6600; color:#FF6600; color:#FF6600; }
</STYLE>
<table width="100%" cellpadding="10" cellspacing="0" bgcolor='#505050' >
<tr>
<td valign="top" align="center">
<table width="600" cellpadding="0" cellspacing="0">
<tr>
<td style="background-color:#ffffff;border-top:0px solid #000000;border-bottom:1px solid #FFFFFF;text-align:center;" align="center"><span style="font-size:10px;color:#000000;line-height:200%;font-family:verdana;text-decoration:none;">Email not displaying correctly? <a href="*|ARCHIVE|*" style="font-size:10px;color:#ff7700;line-height:200%;font-family:verdana;text-decoration:none;">View it in your browser.</a></span></td>
</tr>
<tr>
<td align="left" valign="middle" style="background-color:#505050;border-top:0px solid #333333;border-bottom:10px solid #FFFFFF;"><center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="center"></a></center></td>
</tr>
</table>
<table width="600" cellpadding="20" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="200" valign="top" style="background-color:#FFFFFF;border-right:1px solid #CCCCCC;text-align:left;">
<span style="font-size:11px;font-weight:normal;color:#505050;font-family:arial;line-height:150%;">
<p>
Attention: ' . $name . ',
</p>
<center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="center"></a></center>
<br>
<span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
<br>
<span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
<br>
<center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="center"></a></center>
</span>
</td>
<td bgcolor="#FFFFFF" valign="top" width="400" style="font-size:12px;color:#000000;line-height:150%;font-family:trebuchet ms;"
<p>
<span style="font-size:20px;font-weight:bold;color:#ff7700;font-family:arial;line-height:110%;"></span><br>
<br>
<center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="right"></a></center>
</p>
<p>
<a href="" title=""></a><br><br>
<br><br>
<span style="font-size:15px;font-weight:bold;color:#000000;font-family:arial;line-height:110%;"></span><br>
<br>
<a href="" title=""></a>
</p>
</td>
</tr>
<tr>
<td style="background-color:#505050;border-top:10px solid #FFFFFF;" valign="top" colspan="2">
<span style="font-size:10px;color:#ffffff;line-height:100%;font-family:verdana;">
Trilithon Newsletter <br />
<br />
<a href="" title="Unsubscribe from Newsletter">Unsubscribe</a> *|EMAIL|* from this list.<br />
<br />
Our mailing address is:<br />
<a href="" title=""></a><br />
<br />
Our telephone:<br />
<br />
<br />
Copyright (C) 2007  All rights reserved.<br />
<br />
<a href="*|FORWARD|*" title="Forward to a friend">Forward</a> this email to a friend
</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
';
    $subject = "";
    $headers  = "From:\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "$email";

    $mail_result = mail($to, $subject, $mail_body, $headers);
	
	if ($mail_result) {
		mysql_query("UPDATE mail SET field_9='1' WHERE field_4='$email' LIMIT 1");
	} else {
	   // this else statement can be used to write into an error log if the mail function fails
	   // It can also be removed if you do not need error logging
	}
	
}
?>
<?php
// This section is script I discussed adding to this file on video
// This section is for sending the site owner a message informing them that
// all people in the database have been sent the newsletter for the current campaign
if ($numRows == 0) { // $numRows is set on line 4 using the existing query
	 
	 $subj = "Newsletter Campaign Has Ended";
	 $body = "The current newsletter campaign has ended. All have been sent the newsletter.";
     $hdr  = "From:\r\n";
     $hdr .= "Content-type: text/html\r\n";
     mail("", $subj, $body, $hdr);
	
}
// End Check Section
?>

If someone can help me I would really appreciate it.

Recommended Answers

All 2 Replies

You need to remove any single quotes within the string or escape them with a backslash.

here i fixed it, i escape all the single qoutes(') in your $mail_body string

<?php
include_once "connect_to_mysql.php";
$sql = mysql_query("SELECT * FROM mail WHERE field_9='0' AND field_8='max' LIMIT 20");
$numRows = mysql_num_rows($sql); // Added for "End Campaign Check" at the bottom of this file(not shown on the video)
$mail_body = '';
while($row = mysql_fetch_array($sql)){
	$id = $row["id"];
	$email = $row["field_4"];
	$name = $row["field_5"];
	
	$mail_body = '
<html>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0" bgcolor=\'#505050\' >
<STYLE>
 .headerTop { background-color:#ffffff; border-top:0px solid #000000; border-bottom:1px solid #FFFFFF; text-align:center; }
 .adminText { font-size:10px; color:#ff7700; line-height:200%; font-family:verdana; text-decoration:none; }
 .headerBar { background-color:#e0e0e0; border-top:0px solid #333333; border-bottom:10px solid #FFFFFF; }
 .title { font-size:20px; font-weight:bold; color:#ff7700; font-family:arial; line-height:110%; }
 .subTitle { font-size:11px; font-weight:normal; color:#666666; font-style:italic; font-family:arial; }
 td { font-size:12px; color:#000000; line-height:150%; font-family:trebuchet ms; }
 .sideColumn { background-color:#e0e0e0; border-right:1px solid #505050; text-align:left; }
 .sideColumnText { font-size:11px; font-weight:normal; color:#999999; font-family:arial; line-height:150%; }
 .sideColumnTitle { font-size:15px; font-weight:bold; color:#333333; font-family:arial; line-height:150%; }
 .footerRow { background-color:#505050; border-top:10px solid #FFFFFF; }
 .footerText { font-size:10px; color:#ffffff; line-height:100%; font-family:verdana; }
 a { color:#FF6600; color:#FF6600; color:#FF6600; }
</STYLE>
<table width="100%" cellpadding="10" cellspacing="0" bgcolor=\'#505050\' >
<tr>
<td valign="top" align="center">
<table width="600" cellpadding="0" cellspacing="0">
<tr>
<td style="background-color:#ffffff;border-top:0px solid #000000;border-bottom:1px solid #FFFFFF;text-align:center;" align="center"><span style="font-size:10px;color:#000000;line-height:200%;font-family:verdana;text-decoration:none;">Email not displaying correctly? <a href="*|ARCHIVE|*" style="font-size:10px;color:#ff7700;line-height:200%;font-family:verdana;text-decoration:none;">View it in your browser.</a></span></td>
</tr>
<tr>
<td align="left" valign="middle" style="background-color:#505050;border-top:0px solid #333333;border-bottom:10px solid #FFFFFF;"><center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="center"></a></center></td>
</tr>
</table>
<table width="600" cellpadding="20" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="200" valign="top" style="background-color:#FFFFFF;border-right:1px solid #CCCCCC;text-align:left;">
<span style="font-size:11px;font-weight:normal;color:#505050;font-family:arial;line-height:150%;">
<p>
Attention: \' . $name . \',
</p>
<center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="center"></a></center>
<br>
<span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
<br>
<span style="font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;"></span><br>
<br>
<center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="center"></a></center>
</span>
</td>
<td bgcolor="#FFFFFF" valign="top" width="400" style="font-size:12px;color:#000000;line-height:150%;font-family:trebuchet ms;"
<p>
<span style="font-size:20px;font-weight:bold;color:#ff7700;font-family:arial;line-height:110%;"></span><br>
<br>
<center><a href=""><IMG id=editableImg1 SRC="" BORDER="0" title=""  alt="" align="right"></a></center>
</p>
<p>
<a href="" title=""></a><br><br>
<br><br>
<span style="font-size:15px;font-weight:bold;color:#000000;font-family:arial;line-height:110%;"></span><br>
<br>
<a href="" title=""></a>
</p>
</td>
</tr>
<tr>
<td style="background-color:#505050;border-top:10px solid #FFFFFF;" valign="top" colspan="2">
<span style="font-size:10px;color:#ffffff;line-height:100%;font-family:verdana;">
Trilithon Newsletter <br />
<br />
<a href="" title="Unsubscribe from Newsletter">Unsubscribe</a> *|EMAIL|* from this list.<br />
<br />
Our mailing address is:<br />
<a href="" title=""></a><br />
<br />
Our telephone:<br />
<br />
<br />
Copyright (C) 2007  All rights reserved.<br />
<br />
<a href="*|FORWARD|*" title="Forward to a friend">Forward</a> this email to a friend
</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
';
    $subject = "";
    $headers  = "From:\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "$email";

    $mail_result = mail($to, $subject, $mail_body, $headers);
	
	if ($mail_result) {
		mysql_query("UPDATE mail SET field_9='1' WHERE field_4='$email' LIMIT 1");
	} else {
	   // this else statement can be used to write into an error log if the mail function fails
	   // It can also be removed if you do not need error logging
	}
	
}
?>
<?php
// This section is script I discussed adding to this file on video
// This section is for sending the site owner a message informing them that
// all people in the database have been sent the newsletter for the current campaign
if ($numRows == 0) { // $numRows is set on line 4 using the existing query
	 
	 $subj = "Newsletter Campaign Has Ended";
	 $body = "The current newsletter campaign has ended. All have been sent the newsletter.";
     $hdr  = "From:\r\n";
     $hdr .= "Content-type: text/html\r\n";
     mail("", $subj, $body, $hdr);
	
}
// End Check Section
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.