Hi there, I have a field which the user fills in the previous page to this script, I want the HTML they enter into that to show in the message. I've used a variable to do this.

I've mailed the message out (only me on the DB), I get it through but the variable is shown in the message as $htmlContent. How can I get this to show correctly?

Any pointers really appreciated.

<?php
$htmlContent=$_POST['html'];
$success=$_POST['successEmail'];
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"];
	
	$mail_body = $htmlContent;
    $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
?>

Recommended Answers

All 3 Replies

Anyone got any ideas?

Debug code using:
echo $mail_body = $htmlContent; exit;

See what you have in browser.

commented: Perfect reply, great solution to my problem. +1

Hi, thanks a lot for your answer. That is great way to debug, managed to work out what the issue was thanks to this. Never realised this could be done. Appreciate your time.

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.