4

Visitors can contact staff by means of contact form (visitor needs to submit email as well). This will be stored in DB. Now considering that staff responds to this message, the reply from the staff would be sent to the visitors email directly. Say if the user wants to follow up on the message sent by the staff, I would like the visitor to just hit the reply button in his email service & send me his questions on the same topic, but just retain the ID in the Subject line. So when the visitor send this email, I would like to receive the email & at the same time, try to search in my DB if the ID that is present in the email subject, actually exists in the system. If yes, that would be sent back to the same staff member who handled the response previously or it would be assigned to a new staff member.

That being said, I was thinking of how to do this. The part where I am really held up is when the staff receives the actual email from the visitors email, how can I check the DB? Say I am/staff is receiving emails at mydomain@hotmail.com. When visitor sends reply email, then it would be sent to mydomain@hotmail.com. How can I check to see if the ID in the subject line of the email that I received at mydomain@hotmail.com, actually exists in my DB in my website? This is where I am really stuck.

Looking forward for your replies. Thank you.

Devner
  • 6,825
  • 11
  • 63
  • 104
  • What type of email system are you using? The reason I ask is that each system has a different API. – websch01ar Jun 18 '10 at 13:22
  • Email system? I am sorry I am unclear on what that means. Do you mean what email service provider that I have chosen to send & receive emails? I can use myemail@mydomain.com but I choose to go with an email outside my domain (as I have some issues with processing mail over my domain), ex: myemail@hotmail.com or myemail@yahoo.com. Is that what you needed to know? – Devner Jun 18 '10 at 13:27
  • You would need to do it at server, for example make a default email support@yourdomain.com and let all the users submit emails to it. Then you make a code to receive the emails and register it on the database and it will then forward the email to one of the staff, once the staff reply to it, same thing happens the email goes to support@yourdomain.com and it will be classified as replied by the staff and forwarded to the given user by the support@ email. With this everything that goes in and out will be received and take care by your server script. – Prix Jun 18 '10 at 13:32
  • Depending on how much access it gets you might need to add a crontab schedule so whenever you reiceve a message within minutes it will interact with it. – Prix Jun 18 '10 at 13:33
  • @Prix, thanks for your reply, but it is this part: "receive the emails and register it on the database". When the email is received, it just sits in the mailbox, how do I access the mailbox and the contents of the email that I just received? This is the confusing part that I need help with the most. – Devner Jun 18 '10 at 16:28
  • 1
    Related [How do I receive email and process it in a web application](http://stackoverflow.com/q/965178/367456) – hakre Dec 24 '14 at 11:28

2 Answers2

2

There are several approaches that you can use for automatically processing email. Which one you choose is going to depend upon your specific needs:

  1. Configure your MTA (mail server) to run a program when it receives mail at a given address (eg: support@mydomain.com). The mail message itself will be passed to the program to handle. This works if you have your own mail server, and is the most responsive solution, but can be quite complex to configure and will usually require restarting the mail server to change.

  2. Write a program that periodically scans a mailbox (either with POP or IMAP) and then processes each new message. This works better for situations where you don't control your own mail server (eg: you're using Gmail or Yahoo mail) and is more flexible to configure.

  3. Write an extension for your MUA (mail client eg MS Outlook, Thunderbird, etc.) This requires that everyone who could receive a message be running the same client software, and it depends upon the APIs that your client provides for extensions. This won't work with web-only interfaces, but will allow you to process a message interactively and to interact with the user.

I tend to favor the first approach, though I have used the second approach as well.

Craig Trader
  • 15,507
  • 6
  • 37
  • 55
  • Thank you for the reply. I feel longing for the 2nd option. How exactly can I do that? I don't control anything & I am on a shared server. Option 3 sounds too restrictive. So for opt 2, can you please guide me more on that? I have never done this before. How do I access the incoming mails, check if existing mails have been read or not, etc. I am a complete newbie in this regard so all your help is highly appreciated. – Devner Jun 18 '10 at 16:32
  • For options 2 you did need to learn a programming language if you dont already know one or use a ticket system that is alreay built and available out there such as perldesk... for instance with php http://php.net/manual/en/book.imap.php or with perl http://perldoc.perl.org/Net/POP3.html – Prix Jun 18 '10 at 17:37
  • Hi Prix, I can program in PHP. Not a problem. The issue is with reading the contents of the mail. I have thought of using Gmail to receive emails. Since you have experience, can you please tell me how to access the emails content in Gmail? I don't think Google will lend me their source code so that I can read it & prepare a solution. So what choice do I have here? – Devner Jun 18 '10 at 17:53
  • First thing you have to do is to verify if your php has imap within it, you can try using sockets for pop3 too if u dont have imap available, af for imap it has to be compiled as an option, but most hosts have it you can check that using the which will show what your php has installed, etc... Then if you have imap which is probably the best option check this http://www.php.net/manual/en/function.imap-open.php if dont you can try with sockets, a sample http://www.adamsinfo.com/a-rudimentary-php-pop3-example/ but i am sure someone with better knowledge will cover this. – Prix Jun 18 '10 at 19:09
  • 1
    i still belive you would be better of running this in your own host since you can do pipeling (on cpanel for example: http://www.activecampaign.com/support/tt/index.php?action=kb&article=331 ) on an email so that it goes direct to your code when it arrives... – Prix Jun 18 '10 at 19:13
  • @Prix +1 for the info on the pipe! Awesome! – Martin Feb 19 '11 at 20:13
1

Have a look at this zend library, it is nice and easy to incoporate into your site and means you dont have to try and write some hard code to read a message box etc

Hope it helps

Luke

Luke
  • 3,333
  • 2
  • 28
  • 44
  • thanks for the reply. I have not made use of any frameworks so far & at least till the first version goes live & marks the website as successful, I am afraid I will have to wait on using it. Also I want to be thorough with the framework before I implement it. That way, I will be able to take care of my own errors (as many as possible). But I still do thank you for your efforts to guide me. – Devner Jun 18 '10 at 16:35
  • @Denver, just in case you didn't realise, you can use the mail library without using the zend framework, you can even use a different framework such as symfony and include zend library's. I know it means you have to trust or read the zend library but also is it worth re-inventing the wheel? – Luke Jun 21 '10 at 07:32
  • thanks for informing me about that. I will take a look at it. – Devner Jun 28 '10 at 11:10