From: "Brett" <[EMAIL PROTECTED]>

> 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 = "[EMAIL PROTECTED]";
    $mailsubject = "Thanks for your order";
    $mailbody = ob_get_contents();
    $mailheaders = "From: [EMAIL PROTECTED]\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: [EMAIL PROTECTED]\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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to