writing in database when send an email

Discussion in 'PHP' started by legend19892008, Apr 21, 2009.

  1. #1
    i need to know how to make a script
    a user can send an email to for example (forum@digitalpoint.com)
    once he send that mail ,the message is written automatically in database
    -------
    i see this idea in a lot of ticket systems
    user send support to

    once he send from his mail
    if he opened ticket system script he can find the message he sent by mail
    it is in hosting companies as hostgator,webhosting pad
    http://support.webhostingpad.com/

    any help for how to do such algorithm?
    codes are recommended as i am a php beginner :)
     
    legend19892008, Apr 21, 2009 IP
  2. prxygurl

    prxygurl Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ummm that's as straightforward as it can be... Try something in the line of

    
    $from = $_POST['from'];
    $to = $_POST['to'];
    $subj = $_POST['subj'];
    $msg = $_POST['msg'];
    
    mail($to, $subj, $msg, 'From: ' . $from . "\r\n");
    mysql_query("INSERT INTO tbl VALUES($from, $to, $subj, $msg)");
    
    Code (markup):
    The data should be sent via a form that contains 'from', 'to' and 'subj' as input text boxes and 'msg' (usually textarea). "tbl" is the name of the table where you want the data stored, and a mysql connection should have been created beforehand.
     
    prxygurl, Apr 21, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    1) You need to arrange with your email provider to have incoming messages piped to a script. Not all shared hosts will do that, though it's easy to set up on VPS/dedicated.

    2) You can read the message thusly:

    $message = file_get_contents('php://stdin');
    Code (markup):
    3) The header is separated from the message by a single blank line. If it's a MIME message then you'll have to do more parsing. There are probably PEAR libraries for this but I find PEAR quality to be so uneven that I have stopped considering it.
     
    SmallPotatoes, Apr 21, 2009 IP
  4. Grobbulus

    Grobbulus Peon

    Messages:
    557
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I agree with you. It is most likely the easiest php there is. Search google for anything related to php mail and you will get the same results.
     
    Grobbulus, Apr 21, 2009 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Apart from the fact that the OP probably wanted to parse ALL email correspondece between the email-address (ie. a support address or something similar) and the clients - even if the clients does not use the form on the page, but emails directly to the email-addresse from an emailclient. THAT has to be done on the server while parsing the received emails, and isn't really a PHP-question.
     
    PoPSiCLe, Apr 21, 2009 IP
  6. legend19892008

    legend19892008 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i want the user to send mail from his yahoo mail not to open a script and pos,when he send from his yahoo mail or gmail,the message is written to database
     
    legend19892008, Apr 21, 2009 IP
  7. legend19892008

    legend19892008 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    sworry i cant understand ,more explanation plz
     
    legend19892008, Apr 21, 2009 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    We don't know your hosting service, but what you should do is contact the support at whereever you are hosting your site, and ask what services they provide for parsing received emails to a database. If you are on a dedicated server, where you have full access to all the configuration files, you should hire someone familiar with scripting and the operating system on the box, and have them make you a script.

    Take note, however, that you need to provide some sort of identifying header (or ID-number) on the email (could just be the subject header, or a certain ID-number stored in the email itself) so you know which emails belong to a certain client/support issue (if you base it on the email-address of the sender, all support issues will be put together).

    It is basically something that need to run on the server itself, and there are way better ways to do this than using PHP. If you are on a linux server, python classes and a parsing from the receiving mail-software is probably a good way to do it.
     
    PoPSiCLe, Apr 21, 2009 IP
  9. legend19892008

    legend19892008 Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    i am a vps
    could u help me with links to some of these codes?
     
    legend19892008, Apr 21, 2009 IP
  10. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Unfortunately, if that doesn't make sense to you (or serve as a usable base for googling further) then you'll probably have to hire someone to help you. Not me, though; no free time.
     
    SmallPotatoes, Apr 22, 2009 IP
  11. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #11
    as the simplest method up there, more explaination from me :
    first, send the email, then second, add to database,

    you can not do both action at the same time.
    correct me if i am wrong.
     
    bluebenz, Apr 22, 2009 IP
  12. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #12
    He doesn't want to send mail, he wants to receive it. That requires server integration outside of the PHP context.
     
    SmallPotatoes, Apr 23, 2009 IP