cooldude832 Posted December 31, 2007 Share Posted December 31, 2007 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/ Share on other sites More sharing options...
PHP_PhREEEk Posted December 31, 2007 Share Posted December 31, 2007 eval() executes the code it evals, so of course if you eval echo "whatever", that will be echo'd immediately. Hope you can see why it's doing what it is versus what you expected. You should be able to fix that after understanding why. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426356 Share on other sites More sharing options...
cooldude832 Posted December 31, 2007 Author Share Posted December 31, 2007 I realize that now, but now how could I take the evaluated product and put it into a email body? Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426360 Share on other sites More sharing options...
PHP_PhREEEk Posted December 31, 2007 Share Posted December 31, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426361 Share on other sites More sharing options...
cooldude832 Posted December 31, 2007 Author Share Posted December 31, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426366 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 Don't use the eval() function at all. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426367 Share on other sites More sharing options...
cooldude832 Posted December 31, 2007 Author Share Posted December 31, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426368 Share on other sites More sharing options...
cooldude832 Posted December 31, 2007 Author Share Posted December 31, 2007 like I want to be able to write a dyanimc message that is like <?php echo "Hello ".$row['Username']."<br /> This message was sent on date("d-m-y");" ?> Make more sense? Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426369 Share on other sites More sharing options...
cooldude832 Posted December 31, 2007 Author Share Posted December 31, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/83796-solved-strange-output-on-eval/#findComment-426376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.