Ah I see. This is fairly tricky if you want the user to be able to reply to emails sent from your server in order to "opt-in" or "opt-out". You have two options:
a) Create system filters at the MX server which handles incoming mails, pipe all emails to a PHP script and "read" the email from there. (Recommended)
b) Use the IMAP functions (until of course I create a swift-like IMAP/POP3 lib

) to open the mailbox and do the above job by cron.
For the opt-in you'd have some unique hash in the message, or maybe even just the user-id. For the opt-out you can probably simply suggest sending an email address with "opt-out" in the subject, then look up the email in the database and remove it.