Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Running Script Before Output to File



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

10+ Year Member

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?


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


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

10+ Year Member

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>
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?


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

10+ Year Member

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?

Featured Threads

Hot Threads This Week

Hot Threads This Month