Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

want to receive email (running on shared server)

please see
https://www.experts-exchange.com/questions/27817846/using-php-I-can-send-email-phpmailer-mail-but-can-I-receive-email.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

Avatar of arnold
arnold
Flag of United States of America image

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.
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
Avatar of rgb192

ASKER

what do I do in godaddy linux hosting control pannel
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.
Avatar of rgb192

ASKER

>>  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
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks