Page 538 - Beginning PHP 5.3
P. 538

Part III: Using PHP in Practice
                   How about if you ’ re running on a Windows server? In that case you ’ re in luck. Because PHP on
                 Windows doesn ’ t use an MTA and instead talks directly to an SMTP server, you can easily set the return
                 path in Windows via a   php.ini  setting called  sendmail_from :

                    ini_set( “sendmail_from”, “bob@example.com” );
                    mail( “Jim Smith  < jim@example.com > ”, “Hello”, $message, “From: Bob Jones


                      < bob@example.com > ” );
                  Sending HTML Emails

                   Your message body doesn ’ t have to be plain text; you can send an HTML Web page as an email if you
                 prefer. This allows you to format your message more attractively. However, you need to bear in mind
                 that not all email applications display HTML emails in the same way (or at all), so it ’ s worth testing your
                 HTML email with various email applications before you send it out  —  especially if you ’ re sending the
                 email to a large mailing list  —  and you should also include a plain text version of the message along
                 with the HTML version (you find out how to do this in a moment).

                   To send an HTML email message, you need to do two things:
                      1.       Create the HTML markup for your message body.
                      2.       Send the message using the  mail()  function, passing in additional MIME headers to indicate
                       that the message body is in HTML format.

                      MIME stands for Multipurpose Internet Mail Extensions, and it ’ s an extension to the standard email
                    protocols that allows, among other things, messages to contain multiple text and non - text attachments.
                    MIME is also used in other Internet protocols; in fact you ’ ve already seen the   Content - Type:  MIME
                    header in the  “ Working with HTTP ”  section earlier in the chapter.
                  First, create your HTML message body. At the time of writing, most email applications only understand
                a subset of the full HTML standard, so it ’ s best to make your markup as simple as possible. CSS support
                is particularly bad, so you may find you need to eschew CSS layouts in favor of table - based layouts.

                      You can find out more about creating HTML emails, as well as download some free HTML email
                    templates, from   http://www.mailchimp.com/resources/templates/ . Another useful site is
                    the Email Standards Project (  http://www.email - standards.org/ ) that tracks the state of
                    Web standards support across various email applications.

                   Here ’ s a very simple HTML email message:



                    $message =  < < < END_HTML
                      < html >
                       < body >
                         < h1 style=”color: #AA3333;” > Thank You < /h1 >
                         < p > Thank you for contacting  < a href=”http://www.example.com/” > The Widget
                    Company < /a > . We’ll be in touch shortly. < /p >
                       < /body >
                      < /html >
                    END_HTML;




              500





                                                                                                      9/21/09   9:15:40 AM
          c16.indd   500                                                                              9/21/09   9:15:40 AM
          c16.indd   500
   533   534   535   536   537   538   539   540   541   542   543