SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forward email to php script???

    Ok gurus, gather around.. i got a question for you awesome ppl

    i need to do the following:

    when someone emails me at xyz@mydomain.com i need it to be forwarded to a php script which then reads the content of the subject and body of that email and stores them in a db after processing it and reply's to the sender with confirmation..

    but i cant' figure out how to configure my server to do the forwarding part?

    i am running my site on Dreamhost.com

    cheers

  2. #2
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the email going to be read by a user as well?

    Why forward, you could just setup PHP to IMAP to the account and parse it out, do all your stuff. You wouldn't need to forward an email anywhere.

    You could set up your email address to be a alias that sends a copy to two different email addresses.

    e.g.

    info@mydomain.com: realpeason, parser

    The human could log into realperson@ and the parser could imap into parser@

    You could also setup your parser@ so that it directly pipes the email into your script, depending on your server and if you have access to do that sort of thing. But on a sendmail box you could do something like:

    myemail: '|/pathto/script.php'

    Hope that gives you some ideas.

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks msteudel,

    i tried the sendmail thing but that isn't really working .. could be due to the fact that i am on shared hosting?

  4. #4
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be you may save your self some headache and just ask them if you can do this.

    But try this from the command line:

    mail <flags> | yourscript.php

    Good way to test to see if it works. One thing to make sure is that you hav an interpreter at the top of your script.

    #!/pathto/php

    The other thing is to tail the /var/log/mail (if you have one) file and see if it spits out any errrors.

    Good Luck

  5. #5
    SitePoint Zealot Mau's Avatar
    Join Date
    Jan 2006
    Location
    California, USA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP also has IMAP and POP3 support as an extension: http://php.net/imap

  6. #6
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's some example code for IMAP

    PHP Code:
    <?php


    // set user to check
    $strUser     "username";
    $strPassword "password";

    // open
    $hMail imap_open ("{mail.mailserver.com:143/notls}INBOX""$strUser""$strPassword");

    // get headers
    $aHeaders imap_headers$hMail );

    // get message count
    $objMail imap_mailboxmsginfo$hMail );

    // process messages
    for( $idxMsg 1$idxMsg <= $objMail->Nmsgs$idxMsg++  )
    {
        
    // get header info
        
    $objHeader imap_headerinfo$hMail$idxMsg );

        
    // get from object array
        
    $aFrom $objHeader->from;

        
    // process headers
        
    for( $idx 0$idx count($aFrom); $idx++ )
        {
           
           
    // this is where you would process stuff
        
        
    }

        
    // delete message
        
    imap_delete$hMail$idxMsg );
    }

    // expunge deleted messages
    imap_expunge$hMail );

    // close
    imap_close$hMail );

    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •