13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Implementing Administrative Functions<br />

735<br />

Listing 30.17<br />

Continued<br />

// character used on this system<br />

$message = new Mail_mime("\r\n");<br />

// read in the text version of the newsletter<br />

$textfilename = "archive/".$listid."/".$mailid."/text.txt";<br />

$tfp = fopen($textfilename, "r");<br />

$text = fread($tfp, filesize($textfilename));<br />

fclose($tfp);<br />

// read in the HTML version of the newsletter<br />

$htmlfilename = "archive/".$listid."/".$mailid."/index.html";<br />

$hfp = fopen($htmlfilename, "r");<br />

$html = fread($hfp, filesize($htmlfilename));<br />

fclose($hfp);<br />

// add HTML <strong>and</strong> text to the mimemail object<br />

$message->setTXTBody($text);<br />

$message->setHTMLBody($html);<br />

// get the list of images that relate to this message<br />

$query = "select path, mimetype from images where<br />

mailid = '".$mailid."'";<br />

$result = $conn->query($query);<br />

if(!$result) {<br />

echo "Unable to get image list from database.";<br />

return false;<br />

}<br />

$num = $result->num_rows;<br />

for($i = 0; $ifetch_array();<br />

$imgfilename = "archive/$listid/$mailid/".$row[0];<br />

$imgtype = $row[1];<br />

// add each image to the object<br />

$message->addHTMLImage($imgfilename, $imgtype,<br />

$imgfilename, true);<br />

}<br />

// create message body<br />

$body = $message->get();<br />

// create message headers<br />

$from = '"'.get_real_name($admin_user).'" ';

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!