13.09.2016 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

734 Chapter 30 Building a Mailing List Manager<br />

This code calls the send() function, which you can find in the mlm_fns.php library.<br />

This long function, shown in Listing 30.17, is also the point at which you use the<br />

Mail_mime class.<br />

Listing 30.17 send()Function from mlm_fns.php—This Function Finally Sends Out<br />

a Newsletter<br />

// create the message from the stored DB entries <strong>and</strong> files<br />

// send test messages to the administrator, or real messages to the whole list<br />

function send($mailid, $admin_user) {<br />

if(!check_admin_user($admin_user)) {<br />

return false;<br />

}<br />

if(!($info = load_mail_info($mailid))) {<br />

echo "Cannot load list information for message ".$mailid."";<br />

return false;<br />

}<br />

$subject = $info['subject'];<br />

$listid = $info['listid'];<br />

$status = $info['status'];<br />

$sent = $info['sent'];<br />

$from_name = 'Pyramid MLM';<br />

$from_address = 'return@address';<br />

$query = "select email from sub_lists where listid = '".$listid."'";<br />

$conn = db_connect();<br />

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

if (!$result) {<br />

echo $query;<br />

return false;<br />

} else if ($result->num_rows==0) {<br />

echo "There is nobody subscribed to list number ".$listid."";<br />

return false;<br />

}<br />

// include PEAR mail classes<br />

include('Mail.php');<br />

include('Mail/mime.php');<br />

// instantiate MIME class <strong>and</strong> pass it the carriage return/line feed

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

Saved successfully!

Ooh no, something went wrong!