Forum Moderators: coopster
<?php include('includes/confirmation.php'); // This parses and displays the confirmation page in the web browser
$to = $email;
$subject = "Conference Confirmation";
$message = "<html><body>" . include('includes/confirmation.php') . "</body></html>";
$headers = "From: no-reply@example.com" . "\r\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1" . "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message1, $headers);
?>
An e-mail gets sent, but it has no content. Is it possible to e-mail an included snippet of HTML/PHP like I'm trying? Is there something wrong in my headers?
Thanks!
...but it has no content
When you view source on the 'empty' email, do the html and body tags show up?
Is it possible to e-mail an included snippet of HTML/PHP like I'm trying?
It can be done, but perhaps not the way you are trying.
The way I have done this in the past, was to file_get_contents the page/html in question (your includes/confirmation.php, but to get it from an URL, not an include). This way was the easiest for the implementation I was using.
So $message = file_get_contents('http://www.somepage.com/confirmation.php');
This requires that fopen wrappers have been enabled. See the entry on file_get_contents in php.net for more info.
My includes/confirmation page uses variables that I get from the current page--I insert a whole bunch of information from a form into MySQL at the top of the page and in the actual HTML I show what they just inserted, using variables like $name, $email, etc.
When the confirmation page gets e-mailed, it is not parsed by PHP until getting read by the browser/e-mail viewer, meaning all my variables are dead (since it's a new page).
Is there any way to render/parse the PHP page before e-mailing it out?
Thanks!
These are the same reasons why I did mine this way. It was easiest for us to have the page load at an URL, as this invoked the CMS to run and therefore we had access to the DB and could fill in the necessary vars.
So I guess that is your answer. Find a way to get the necessary data and to fill in the vars of your page before file_get_contents. Sorry I cannot be of more help, but w/out knowing your exact system the answer becomes a little abstract.
I finally got something to work. Rather than use HTML e-mail, I did it all in plain text (although I could have done it in HTML now that I think of it)
Before my confirmation include, I started a $message variable with some initial e-mail text. In the confirmation page where the confirmation was automatically generated, I inserted $message .= "whatever\n\n" in each of the sections that got rendered. For example:
<?php
if ($volunteer=="yes"){
?>
<tr>
<th></th>
<td>I would like to volunteer at this event</td>
<tr>
<?php
$message .= "I would like to volunteer at this event\n\n";
}
?>
By the end of going through all the confirmation logic, $message was big and long, but e-mailable in with mail(). Roundabout solution, yes, but it worked.