2

I'm working on a system where, if a customer submits an order, they get a confirmation email. However, I'd like to make the following happen. if the customer then hits reply, and replies to this email address, I want their message to not go to that email address, but rather be stored in a MySQL database on the server.

Is there a way to 'intercept' and email in this way?

1
  • Depends on your host, my host (Bluehost) allows me to set up an email address that when messages come in a script handles them. Look through your CPanel or contact support to see if they offer something similar. Commented Sep 4, 2012 at 12:40

6 Answers 6

6

Have the reply to address set up to go straight into a mailbox that you can access using PHP's imap_open to access and read emails. Armed with that, it should be a simple matter to insert the data as required into a database.

<?php
$mbox = imap_open("{imap.example.org:143}", "username", "password");

echo "<h1>Mailboxes</h1>\n";
$folders = imap_listmailbox($mbox, "{imap.example.org:143}", "*");

if ($folders == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />\n";
    }
}

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);
?>

The full list of PHP IMAP functions is very thorough.

Sign up to request clarification or add additional context in comments.

Comments

1

It isn't a possible way directly without a mail box.

But you can do a special mailbox for that and fetch emails to imap_* functions from PHP and based on the subject or email to save them in database and then delete that email.

Comments

1

Using PHP IMAP functions you can read in the mails sent to a specific address. You can't however make it not send to that address. But you can use the mail, put it in the database and delete it.

Comments

0

I don't think there's a way to do that easily. What you can do is have a reply-to header in your email and send it to a monitored mailbox that a daemon-type service would periodically check for new emails and do its work.

Comments

0

You can check following link and resources:

  1. http://framework.zend.com/manual/en/zend.mail.read.html

  2. http://code.google.com/p/php-imap

Or you can follow this SO question

Comments

0

Yes, it is possible. Have a look here: http://www.mddhosting.com/support/knowledgebase/1011/Email-Piping-to-a-PHP-Script-in-cPanel-x3-Theme.html

and another one: http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.