Jump to content

[SOLVED] Strange output on eval?


cooldude832

Recommended Posts

I'm trying to use eval to make dynamic emails

my snippete looks like this

<?php
foreach($data as $key => $value){
	$subject = $email_body[$value['BatchID']]['Subject'];
	$body = eval($email_body[$value['BatchID']]['Body']);
	echo "<div>Subject: ".$subject."<br />Body:".$body."<br /><hr /><br /></div>\n\n";
}
?>

It produces some code outta order in the document

it looks like

<center>Hello World!</center><div>Subject: Test<br />Body:<br /><hr /><br /></div>

 

<center>Hello World!</center><div>Subject: Test<br />Body:<br /><hr /><br /></div>

 

when I expected

<div>Subject: Test<br />Body:<br /><center>Hellow World!</center></hr /><br /></div>

 

 

<div>Subject: Test<br />Body:<br /><center>Hellow World!</center></hr /><br /></div>

 

 

any ideas?

$body looks like this un evaluated

echo "<center>Hello World!</center>";

Link to comment
https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/
Share on other sites

<?php
foreach( $data as $key => $value ) {
    $subject = $email_body[$value['BatchID']]['Subject'];
    $body = ;
    echo "<div>Subject: " . $subject . "<br />Body:" . eval($email_body[$value['BatchID']]['Body']) . "<br /><hr /><br /></div>\n\n";
}
?>

 

PhREEEk

well this is what I tried, but the message sends with a blank body?

<?php
foreach($data as $key => $value){
	$subject = $email_body[$value['BatchID']]['Subject'];
	$body = $email_body[$value['BatchID']]['Body'];
	$headers = "From: ".FROM_ACCOUNT." <webmaster@".$domain.">\r\n";
	$headers .= "Reply-To: webmaster@".$domain."\r\n";
	$headers .= "Return-Path: webmaster@".$domain."\r\n";
	$headers .= "X-Mailer: PHP/" . phpversion()."\r\n";
	$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
	if(mail($value['Email'],$subject,eval($body),$headers)){
		$sent_messages[]  = "SendID = ".$value['SendID'];
	}
	else{
		$not_sent_messages[] = "SendID = ".$value['SendID'];
	}
}
?>

and the page says the body message on it so I'm confused

 

 

The mail still sends with proper headers and subject but empty body?

let me explain what i'm doing and maybe you got a better idea

I have a page that sets up emails to be distributed at a certain time and I want to include info like the users name or other account data in the email

so I figure if I write the whole message as php and say stuff like

echo $data['Username'];

I could gain access to the variables

However its not working as I expected so any ideas?

here is what I came up with, limits me a bit but works

the sending part

<?php
$sent_messages = array();
$not_sent_messages = array();
foreach($data as $key => $value){
	$subject = $email_body[$value['BatchID']]['Subject'];
	$body = body_phrase($email_body[$value['BatchID']]['Body'],$value['UserID']);
	echo "UserID: ".$value['UserID']."<br />";
	$headers = "From: ".FROM_ACCOUNT." <webmaster@".$domain.">\r\n";
	$headers .= "Reply-To: webmaster@".$domain."\r\n";
	$headers .= "Return-Path: webmaster@".$domain."\r\n";
	$headers .= "X-Mailer: PHP/" . phpversion()."\r\n";
	$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
	if(mail($value['Email'],$subject,$body,$headers)){
		$sent_messages[]  = "SendID = ".$value['SendID'];
	}
	else{
		$not_sent_messages[] = "SendID = ".$value['SendID'];
	}
}
?>

and the function body_phrase

<?php
function body_phrase($body,$userid){
$replacements = array("[username]", "[code]", "[LastLogin]");
$fields = array("Username", "Register_Code", "LastLogin");
foreach($replacements as $key => $value){
	$body = str_replace($value, $GLOBALS['user_data'][$userid][$fields[$key]], $body);
}
return $body;
}

 

It gets me to what I need so I'm happy[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.