[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Reply to E-mail that came form webiste? Then Track it back into website?

You've received an e-mail before from a ticketing system or a website messaging... where it says "You can reply directly to this e-mail" instead of logging back into the web site to send the message. How do they do this?

My server is a Linux, running Apache2.0, PHP 5.3 (upgrading atm),  Qmail mail/Sendmail.... Where do I start?
http://test.ahaworldcampus.com/phpinfo.php

Even just an article or something... or a keyword to put in google because I can't even figure out what to search for, lol.

Thanks!
0
tonyhhisc
Asked:
tonyhhisc
  • 3
  • 2
  • 2
1 Solution
 
Bryan ButlerCommented:
Do you want to "post" the email to the website?  Such as this:

http://codex.wordpress.org/Post_to_your_blog_using_email
0
 
tonyhhiscAuthor Commented:
Yes that's pretty much the same thing I'm looking for. But of course I'm not using wordpress.

The functionality of sending an e-mail to create a post (or execute a function) on my web site is what I'm looking for.

I want to send an e-mail to:

someaddress@myserver.com

Maybe with the subject line containing "[9282-9424] RE: blah blah"

I've seen it done like that before.... I think the [9282-9424] is the id of the message and the user id. As long as that's in the subject line, it will post everything back to the website.


0
 
Bryan ButlerCommented:
The content management systems do this type of thing and they add lots of bells and whistles, many of which you will probably want such as screening out words, large posts and other thing you might not want posted on the web site.  Also they handle security as this can be a easy hole to hack.  If you want to write your own, plan on it being a big project.  I'd look at some of the opern source CMSs that do this and see what the code does.  Here's a link that talks about it:

http://www.phpbuilder.com/board/showthread.php?t=10353564
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Ray PaseurCommented:
The thing you want is called an email pipe script.  It is an script that is started automatically by the server whenever email is received at a certain email address.  The pipe script gets access to the entire email message, including all headers.  The pipe script can then take information from the email and use it to process the contents of the message.  

In the example with a subject containing [9282-9424] that string of numbers is a unique id that enables the pipe script to find a row in the data base.

The pipe script can do anything that any other PHP script can do - read and write to the data base, etc (see line 55).  However because it is started asynchronously it does not have any place to put browser output.  Thus debugging can be troublesome.  The example in the code snippet shows how I have used the mail command with a pipe script.  In that design pattern I am able to see what the pipe got for input, as well as any messages I might want to issue from the pipe script.  Parse errors, obviously, are hard to detect, so rely on your error_log to find those.

HTH, ~Ray
#!/usr/bin/php -q
<?php // /email_pipe/index.php


// THIS IS AN EMAIL PIPE SCRIPT.
// THIS SCRIPT IS STARTED AUTOMATICALLY FOR EACH MESSAGE.
// NOTE THAT THIS SCRIPT IS ABOVE THE /public_html/ DIRECTORY TO PREVENT ACCIDENTAL EXECUTION


// --> HOW DO WE KNOW WHICH EMAIL MESSAGES GET SENT HERE?
// THIS SCRIPT RECEIVES MESSAGES SENT TO email_pipe@your.org
// CREATE AN EMAIL MAILBOX EXCLUSIVELY FOR AUTOMATED PROCESSING.
// SET UP AN EMAIL FORWARD FOR THAT MAILBOX IN cPANEL->EMAIL LIKE THIS:
// 1...5...10...15...20...25...
// |/home/{account}/email_pipe/index.php


// --> WHEN YOU UPLOAD, THIS SCRIPT WILL BE MARKED RW-R-R BUT THAT IS WRONG
// THIS SCRIPT MUST BE MARKED EXECUTABLE x0755
// YOU CAN USE FTP SOFTWARE TO CHMOD TO RWX-RX-RX


// --> NOTE THE FIRST LINE OF THIS SCRIPT MUST SAY #!/usr/bin/php -q STARTING IN COLUMN ONE
// 1...5...10...15...20...25...
// #!/usr/bin/php -q
// <?php ... PROGRAM CODE FOLLOWS


error_reporting(E_ALL);

// USE THE OUTPUT BUFFER - THIS DOES NOT HAVE BROWSER OUTPUT
ob_start();

// COLLECT THE INFORMATION HERE
$raw_email = NULL;

// TRY TO READ THE EMAIL FROM STDIN
if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin " . PHP_EOL;
}

// ABLE TO READ THE MAIL
else
{
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}


// REMOVE MULTIPLE BLANKS - AND OTHER PROCESSING AS MIGHT BE NEEDED
$raw_email = preg_replace('/ +/', ' ', $raw_email);

// SPEW WHAT WE GOT, IF ANYTHING, INTO THE OUTPUT BUFFER
var_dump($raw_email);

// CAPTURE THE OUTPUT BUFFER AND SEND IT TO SOMEONE ELSE VIA EMAIL
$buf = ob_get_contents();
mail ('you@your.org', 'EMAIL PIPE DATA', $buf);
ob_end_clean();

Open in new window

0
 
Bryan ButlerCommented:
Good answer Ray.  I'm curios though.  How is the script started?  Does the mail server tell apache to run it?  
0
 
Ray PaseurCommented:
Yes, I think that is how it works (haven't used one in a while).  See lines 10-15 of the code for how I set it up.  If you don't have cPanel, your hosting company can probably set it up for you.
0
 
tonyhhiscAuthor Commented:
Excellent!! Many Thanks!
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now