homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Running Script Before Output to File
TheRealTerry




msg:1300207
 1:59 am on Dec 15, 2005 (gmt 0)

I've got an HTML emailer system where the user creates an HTML file with their input from a form. I've had no problem with this part, neither with the email sending and display HTML. However, before the contents of the HTML email (the HTML file the user creates) gets applied as the message body and emailed via PHP, I would like the file to be passed through PHP and any scripts run that happen to be on the template. My actual portion of email code is here (where the file is read into a variable and the mail is sent):


$emailHeaders = "From: info@domain.com\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
$emailMessage = file_get_contents(path/filetosend.php);
$emailSubject = "Email Subject";
$emailRecipient = recipient@domain.com;
mail($emailRecipient, $emailSubject, $emailMessage, $emailHeaders);

How do I make any PHP scripts that are in the "filetosend.php" run before the output is stored into $emailMessage and mailed off?

 

FalseDawn




msg:1300208
 2:43 am on Dec 15, 2005 (gmt 0)

[us3.php.net...]

TheRealTerry




msg:1300209
 3:43 am on Dec 15, 2005 (gmt 0)

I think that definitely gets me in the right direction, but now I'm running into this:

Parse error: parse error, unexpected T_LNUMBER in .../HTMLEmailer.php(37) : eval()'d code on line 16

I adjusted the above code to process my variable like this:


$emailMessage = file_get_contents(path/filetosend.php);
eval("\$emailMessage = \"$emailMessage\";");

The part of the file trying to be eval'ed up to line 18 is as follows:


1 - <?php
2 - $article1 = '1';
3 - $article2 = '';
4 - $article3 = '';
5 - $article4 = '';
6 - $article5 = '';
7 -?>
8 - <HTML>
9 - <HEAD>
10- <TITLE>Message Subject</TITLE>
11- </HEAD>
12- <BODY>
13- <CENTER>
14- <TABLE BORDER='0' CELLSPACING='0' WIDTH='580'>
15- <TR>
16- <TD WIDTH='580' HEIGHT="100" COLSPAN='2'><A HREF='http://www.domain.com'><IMG SRC='http://www.domain.com/images/headerLogo.gif' BORDER='0'></A></TD>
17- </TR>
18- <TR>

The email gets sent just as before without any PHP processed, it appears to be choking somewhere around the top graphic and link, and the only thing I can see different is the "//" of the URL, so I removed everything between the table divider tags on that line and still get the same result. Any ideas on that?

FalseDawn




msg:1300210
 5:34 am on Dec 15, 2005 (gmt 0)

I don't know much about eval as I never use it, but from reading the comments at the link I posted, you might have difficulty mixing PHP with HTML as you are doing.
You could try replacing the inline HTML with corresponding echos maybe?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved