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.

684 Chapter 29 Building a <strong>Web</strong>-Based Email Service<br />

As you can see, this function uses mail() to send the email. First, however, it loads the<br />

user’s email address out of the database to use in the From field of the email.<br />

Replying To or Forwarding Mail<br />

The Reply, Reply All, <strong>and</strong> Forward functions all send mail in the same way that New<br />

Message does.The difference in how they work is that they fill in parts of the new message<br />

form before showing it to the user. Look back at Figure 29.8.The content of the<br />

message being replied to has been indented with the > symbol, <strong>and</strong> the Subject line prefaced<br />

with Re:. Similarly, the Forward <strong>and</strong> Reply All options fill in the recipients, subject<br />

line, <strong>and</strong> indented message.<br />

The code to reply to or forward mail is activated in the body section of index.php,<br />

as follows:<br />

case 'reply-all':<br />

//set cc as old cc line<br />

if(!$imap) {<br />

$imap = open_mailbox($_SESSION['auth_user'],<br />

$_SESSION['selected_account']);<br />

}<br />

if($imap) {<br />

$header = imap_header($imap, $messageid);<br />

if($header->reply_toaddress) {<br />

$to = $header->reply_toaddress;<br />

} else {<br />

$to = $header->fromaddress;<br />

}<br />

$cc = $header->ccaddress;<br />

$subject = "Re: ".$header->subject;<br />

$body = add_quoting(stripslashes(imap_body($imap, $messageid)));<br />

imap_close($imap);<br />

}<br />

display_new_message_form($_SESSION['auth_user'],<br />

$to, $cc, $subject, $body);<br />

break;<br />

case 'reply':<br />

//set to address as reply-to or from of the current message<br />

if(!$imap) {

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

Saved successfully!

Ooh no, something went wrong!