Page 1 of 1

HTML CSS PHP Email......confusion?

Posted: Thu Oct 05, 2006 10:10 am
by mikeeeeeeey
Hey there,

I'm having quite a lot of trouble with an email at the moment. The email is formed from a database, which is extracted by PHP. This is then put between html tags and then emailed.

If I output ie.

Code: Select all

print($message);
the email looks fine, however when emailed it looks terrible on mac and pc, the formatting is allover the place and the images aren't loading because of gaps in the image src url's (not there in the program).

Help!!! many thanks in advace :o)

here's the code:

Code: Select all

foreach ($_POST['sendTo'] as $sendTo)
{
	$sql = "SELECT * FROM `newsletter` WHERE `checked` =1 ORDER BY ID ASC";
	$result = mysql_query($sql);
	$url = "http://www.myhosting.com/";
	$message .= '<html><head></head><body>';
	$message .= '<table align=\'center\' cellpadding=\'0\' cellspacing=\'0\'>';
	$message .= 	'<tr><td><img src=\'' . $url . 'newsletter/images/header.jpg\' /></td></tr>';
	$message .= 	'<tr><td align=\'right\' valign=\'bottom\' style=\'font-family:Arial;font-size:14px;text-transform:uppercase;padding:0px 58px 0px 0px\'>THIS MONTH FEATURING<br/><span style=\'color:#666666\'>' . $thisdate . '</span>';
		$message .= '</td></tr><tr><td>';
		while ($row = mysql_fetch_array($result))
		{
			$message .= '<table width=\'595\' cellpadding=\'0\' cellspacing=\'0\'>';
			$message .= 	'<tr><td colspan=\'3\'><img src=\'' . $url . 'newsletter/images/top_left.jpg\' />';
			switch ($row[5])
			{
				case 0:
					$txColor = '#333333';
					$message .= '<img src=\'' . $url . 'newsletter/images/general.gif\' />';
				break;
				case 1:
					$txColor = '#A06345';
					$message .= '<img src=\'' . $url . 'newsletter/images/new_media.gif\' />';
				break;
				case 2:
				        $txColor = '#715E3D';
					$message .= '<img src=\'' . $url . 'newsletter/images/creative.gif\' />';
				break;
	
				$message .= '</td></tr>';
			        $message .= 	'<tr><td colspan=\'3\' bgColor=\'#CDC8C4\' style=\'padding:0px 58px 0px 57px'><table cellpadding='0' cellspacing='0'><tr><td colspan='2' align='right' height='50' valign='middle' style='font-family:Arial;font-size:14px;color:' . $txColor . ';text-transform:uppercase\'>' . $row[3] .'</td></tr>';
				$message .= 	'<tr><td valign=\'top\'>';
				if ($row['image'] != NULL)
				{
					$message .='<img width=\'230px\' height=\'150px\' src=\'' . $url . 'newsletter/header_images/'. $row[6] . '' />';
				}
				$message .= '</td><td width=\'595\' align=\'right\' valign=\'top\' style=\'font-family:Arial;font-size:10px;color:#FFFFFF;text-transform:uppercase;padding-left:3px\'><font style=\'color:FFFFFF;font-size:10px;text-transform:uppercase\'>' . $row[4] . '</font></td></tr></table>';
				$message .= 	'</td></tr><tr><td><img src=\'' . $url . 'newsletter/images/left_corner.jpg\' /></td><td width=\'580\' bgColor=\'#CDC8C4\'>&nbsp;</td>';
				$message .= 	'<td><img src=\'' . $url . 'newsletter/images/right_corner.jpg\' /></td></tr></table><br/>';
			}
					$message .= 'To unsubscribe <a style=\'font-family:Arial;font-size:10px;color:#333333\' href=\' . $url . 'newsletter/removeMe.php?email=';
					$message .= $sendTo;
					$message .= '\'>click here</a>';
					$message .= '</td></tr></table></body></html>';	
				
				print($message);
				
				if($sendTo != NULL)
				{
					if (mail($sendTo, $subject, $message, $headers))
					{
						$success = 1;
						print("The newsletter has been sent to " . $sendTo . "<br/>");
					}
					else
					{
						print("The email has not been sent.");
					}
				}
}

Re: HTML CSS PHP Email......confusion?

Posted: Thu Oct 05, 2006 10:20 am
by DaveTheAve
Why don't we try implamenting a \r\n to the end of every line to help the formatting; however, doing this requires you to change from single quotes to double quotes.

Posted: Thu Oct 05, 2006 10:59 am
by mikeeeeeeey
You legend!!! That totally worked.

Thanks a lot :o)