Solved

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

Posted on 2011-09-09
7
253 Views
Last Modified: 2013-12-18
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
Comment
Question by:tonyhhisc
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36511025
Do you want to "post" the email to the website?  Such as this:

http://codex.wordpress.org/Post_to_your_blog_using_email
0
 

Author Comment

by:tonyhhisc
ID: 36511175
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
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36512266
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
Are end users causing IT problems again?

You’ve taken the time to design and update all your end user’s email signatures, only to find out they’re messing up the HTML, changing the font and ruining the imagery. What can you do to prevent this? Find out how you can save your signatures from end users today.

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 36516230
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
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36529331
Good answer Ray.  I'm curios though.  How is the script started?  Does the mail server tell apache to run it?  
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36529489
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
 

Author Closing Comment

by:tonyhhisc
ID: 36530388
Excellent!! Many Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now