0

I have an email blast script as below. The mail_body is taken from a variable which the users sumbits their HTML for the message to be sent, it's send through with lots of \\\ in their for some reason?

The Blast Script

<?php
$prodid='Kriss';
$htmlContent=$_POST['htmlContent'];
include_once "connection.php";
$sql = mysql_query("SELECT * FROM addresses WHERE received='1' 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["email"];
	
	echo $mail_body = $htmlContent; exit;
    $subject = "TEST EMAILER";
    $headers  = "From:info@mifsuds.com\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 addresses SET received='0' WHERE email='$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:info@mifsuds.com\r\n";
     $hdr .= "Content-type: text/html\r\n";
     mail("krissdkerr@gmail.com", $subj, $body, $hdr);
	
}
// End Check Section
?>

HTML Entered into the Form

<html>
<head>
<title>Christmas is Coming at Chic Hair Design</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (November.psd) -->
<table id="Table_01" width="770" height="1309" border="0" cellpadding="0" cellspacing="0" align="center">
	<tr>
		<td width="770" height="43" style="font-family: Arial, Helvetica, sans-serif; font-size: 10px; text-align: center;">Please add info@chichairandbeauty.co.uk to your address book or safe list to ensure our emails reach your inbox.<br/>
Having trouble viewing this email? <a href="http://www.chichairandbeauty.co.uk/mailers/november-christmas.html">View it as a Web page</a>.</td>
	</tr>
	<tr>
		<td>
			<img src="http://www.chichairandbeauty.co.uk/images/November_02.jpg" width="770" height="1174" alt=""></td>
	</tr>
	<tr>
		<td>
			<a href="http://www.facebook.com/pages/Newton-Abbot-United-Kingdom/Chic-Hair-Beauty/113629362006394">
				<img src="http://www.chichairandbeauty.co.uk/images/November_03.jpg" width="770" height="42" border="0" alt=""></a></td>
	</tr>
	<tr>
		<td>
			<a href="http://chic:8888/optout.php?e='.$email.'">
				<img src="http://www.chichairandbeauty.co.uk/images/November_04.jpg" width="770" height="56" border="0" alt=""></a></td>
	</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>

Outputted HTML

<html>
<head>
<title>Christmas is Coming at Chic Hair Design</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>
<body bgcolor=\"#FFFFFF\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">
<!-- Save for Web Slices (November.psd) -->
<table id=\"Table_01\" width=\"770\" height=\"1309\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">
	<tr>
		<td width=\"770\" height=\"43\" style=\"font-family: Arial, Helvetica, sans-serif; font-size: 10px; text-align: center;\">Please add info@chichairandbeauty.co.uk to your address book or safe list to ensure our emails reach your inbox.<br/>
Having trouble viewing this email? <a href=\"http://www.chichairandbeauty.co.uk/mailers/november-christmas.html\">View it as a Web page</a>.</td>
	</tr>
	<tr>
		<td>
			<img src=\"http://www.chichairandbeauty.co.uk/images/November_02.jpg\" width=\"770\" height=\"1174\" alt=\"\"></td>
	</tr>
	<tr>
		<td>
			<a href=\"http://www.facebook.com/pages/Newton-Abbot-United-Kingdom/Chic-Hair-Beauty/113629362006394\">
				<img src=\"http://www.chichairandbeauty.co.uk/images/November_03.jpg\" width=\"770\" height=\"42\" border=\"0\" alt=\"\"></a></td>
	</tr>
	<tr>
		<td>
			<a href=\"http://chic:8888/optout.php?e=\'.$email.\'\">
				<img src=\"http://www.chichairandbeauty.co.uk/images/November_04.jpg\" width=\"770\" height=\"56\" border=\"0\" alt=\"\"></a></td>
	</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>

Edited by coxdabd: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by coxdabd
0

Hi guys, worked out what was wrong (best way to learn). I need to add stripslashes to my variable. If anyone comes across this topic, you need to add the following:

$htmlContent=stripslashes($_POST['htmlContent']);

Instead of:

$htmlContent=$_POST['htmlContent'];

Hope this helps someone.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.