tailieunhanh - PHP and MySQL Web Development - P141

PHP and MySQL Web Development - P141: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 672 Chapter 28 Building a Mailing List Manager message- setTXTBody text message- setHTMLBody html We then load the image details from the database and loop through them adding each image to the piece of mail we want to send load each image from disk imgfilename archive listid mailid .mysql_result result i 0 imgtype mysql_result result i 1 add each image to the object message- addHTMLImage imgfilename imgtype imgfilename true The parameters we pass to addHTMLImage are the name of the image file or we could also pass the image data the MIME type of the image the filename again and true to signify that the first parameter is a filename rather than file data. If we wanted to pass raw image data we would pass the data the MIME type an empty parameter and false. These parameters are a little cumbersome. At this stage we need to create the message body. We need to do this before we can set up the message headers. We create the body as follows create message body body message- get We can then create the message headers with a call to Mail_mime s headers function create message headers from .get_real_name admin_user . . admin_user. hdrarray array From from Subject subject hdrs message- headers hdrarray Finally having set up the message we can send it. In order to do this we need to instantiate the PEAR Mail class and pass to it the message we have created. We begin by instantiating the class as follows create the actual sending object sender Mail factory mail The parameter mail here just tells the Mail class to use PHP s mail function to send messages. We could also use sendmail or smtp as the value for this parameter for the obvious results. Next we send the mail to each of our subscribers. We do this by retrieving and looping through each of the users subscribed to this list and using either the Mail send or regular mail depending on the user s MIME type preference Next 673 if subscriber 2 H send HTML version to people who want it sender- send subscriber 1 hdrs body else

TỪ KHÓA LIÊN QUAN