?
Solved

want to receive email (running on shared server)

Posted on 2012-08-16
7
Medium Priority
?
383 Views
Last Modified: 2012-08-25
please see
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_27817846.html


how can this code be run on godaddy shared hosting

do I save as email.php and run from a browser
or does this work similar to paypal ipn where the data arrives to me



#!/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
Comment
Question by:rgb192
  • 3
  • 3
7 Comments
 
LVL 81

Expert Comment

by:arnold
ID: 38303613
Need clarification on Receive email.
To receive email, you have to have a server/service that is running and listening on port 25.  The other part is that the IP the system has has to be public directly or indirectly.
a shared host will not let you setup your own service, including email. They will not open port 25 from a public IP to the internal IP of the server.
The short answer you can not.

You can setup a PHP page that will let users type in an "email" which you will store in your database and generate an email notification that an "email" has been received.
Presumably this is what you want, i.e. allow users "exchange  emails" within the confines of your site.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38306936
do I save as email.php and run from a browser
or does this work similar to paypal ipn where the data arrives to me
The latter.  This script needs to run on Linux.  I have made no effort to test it on Windows, and things would probably be different there.  It depends on cPanel for the comments to be exactly accurate, however there are probably other control-panel ways to set this up.  It is an asynchronous script with no browser output. Once set up, when an email arrives to the designated address, this script gets control and gets to read the incoming email from STDIN.  This will work on shared hosting because the host will route the email correctly (at least that has been my experience).

Once set up, any email that comes to the designated email address will be presented to this script.

One of the things you want to do as soon as you find that you have the script working is add the output of phpinfo() to the data captured by the script.  You will probably find that the PHP environment is not the same in the PIPE as it would be in the traditional WWW scripts.  You may need to change things like data base connectivity and checking of environmental variables.  There is, obviously, no session for this script since it is completely asynchronous, and there cannot be any clickable links -- nobody at the controls to click a link!

HTH, ~Ray
0
 

Author Comment

by:rgb192
ID: 38315033
what do I do in godaddy linux hosting control pannel
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38315712
I don't know.  I do not use GoDaddy or SiteGround any more.  There are too many good hosting companies for me to waste my time on the "cheap" hosting companies.

Sorry to have to tell you this, but you will need to call GoDaddy tech support and ask them how to set this up.  When you call, if your experience is anything like mine has been in the past, you may get put on hold for a long time on a toll call.  Then someone may answer who clearly has no idea what you're talking about.  That person may tell you that GoDaddy does not support application problems, and they may try to get you to hang up and go away.  

Here's what to say, "Please escalate this problem to your manager immediately.  It is an emergency."  That is the only way I have been able to get GoDaddy to provide any support.

Maybe things have changed at GoDaddy and maybe you will have a pleasant and productive response from them.  Or maybe you would find that LiquidWeb or HostGator are good hosting companies.  I use and recommend ChiHost.com since I have found their tech support to be quick, responsive and accurate.
0
 

Author Comment

by:rgb192
ID: 38319506
>>  There are too many good hosting companies for me to waste my time on the "cheap" hosting companies.

what hosting company do you think the script will work
I can sign up
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38322761
LiquidWeb or HostGator are good hosting companies.  I use and recommend ChiHost.com.  Tell them that you need the Email Pipe capability when you speak to them, and ask them to show you how it gets set up.
0
 

Author Closing Comment

by:rgb192
ID: 38333415
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

862 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