Re: stumped on mailing a complete page

From: Date: Sun, 04 Mar 2001 02:34:43 +0000
Subject: Re: stumped on mailing a complete page
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-42487@lists.php.net to get a copy of this message
From: "Brett" <brett@jnewman.net> > This question may have been asked a million times, but I have had no luck > searching for a difinitive answer. > > I want to send a confirmation email upon receiving an order, and would like > to send the page that I display on the browser to the user. > > I can not figure out how to send a page, like the links that let you mail a > page to a friend on some sites. Any help would be much appreciated. > > Thanks, > Brett If you want to email them the same page that you sent to the browser, you can do this using output buffering. In your confirmation page: <?php ob_start(); // turn on output buffering echo "<html>"; ?> Thanks for your order! <?php echo "</html>"; // now mail the page $mailto = "customer@aol.com"; $mailsubject = "Thanks for your order"; $mailbody = ob_get_contents(); $mailheaders = "From: brett@jnewman.net\nContent-Type: text/html"; mail($mailto, $mailsubject, $mailbody, $mailheaders); // and output the page to the browser ob_end_flush(); ?> But not all mail clients can read HTML email, so it is a good idea to provide a plain text version of the email as well. You can put both versions of the mail in the one message using MIME. Try changing the above code slightly, as follows: <?php ... $mailbody = <<<END This is a multi-part message in MIME format. ------=_NextPart_ Content-Type: text/plain (Here goes the plain-text version of the email.) Dear Customer, Thanks for your order. ------=_NextPart_ Content-Type: text/html END; $mailbody .= ob_get_contents(); // inserts the HTML version $mailbody .= "\n\n------=_NextPart_"; $mailheaders = "From: brett@jnewman.net\n" . "MIME-Version: 1.0\n" . "Content-Type: multipart/alternative;\n" . " boundary=\"----=_NextPart_\""; mail($mailto, $mailsubject, $mailbody, $mailheaders); ... ?> Have a flick through: http://www.php.net/manual/en/ref.outcontrol.php http://www.php.net/manual/en/function.mail.php Cheers Simon Garner

« previous php.general (#42487) next »