1
votes

I want to run a PHP program when receiving emails, and so far, I've had no luck. I have this code in the "Set Default Address" page on cPanel:

enter image description here

mailhandler.php contains the following PHP code:

#!/usr/local/lib/php -q
<?php

  $DataBase = array(
                      'host' => 'localhost',
                      'port' => 3306,
                      'username' => 'dbusername',
                      'password' => 'dbpassword',
                      'database' => 'dbdatabase',
                    );

  // Establish secure database connection
  $DB = @new mysqli($DataBase['host'], $DataBase['username'], $DataBase['password'], $DataBase['database'], $DataBase['port']);


  $DB->query("INSERT INTO test (text) VALUES('Mail received!')");
?>

I've tried running the PHP script from the browser, and the text "Mail received!" is stored into the table. However, when I send a mail, nothing happens. I receive the email on my email account, but nothing is inserted into the database.

Edit: I am receiving the following mail when trying to send a mail to my server:

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

pipe to |/home/MY USERNAME HERE/public_html/mailhandler.php generated by MY EMAIL HERE local delivery failed

The following text was generated during the delivery attempt:

------ pipe to |/home/MY USERNAME HERE/public_html/mailhandler.php generated by MY EMAIL HERE ------

Could not exec '/home/MY USERNAME HERE/public_html/mailhandler.php'

------ This is a copy of the message, including all the headers. ------

Return-path: Received: from mail-qa0-f67.google.com ([209.85.216.67]:64353) by SERVER URL HERE with esmtps (TLSv1:RC4-SHA:128) (Exim 4.82) (envelope-from ) id 1WeXDD-0006Pe-Nn for MY EMAIL HERE; Mon, 28 Apr 2014 02:06:17 +0400 Received: by mail-qa0-f67.google.com with SMTP id dc16so744105qab.2 for ; Sun, 27 Apr 2014 15:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=uuzTLjs2Sa8uqU2HBL4i1frXIc2i13Cxtg9X0Mykahg=; b=A/0fGQwjV6g1G+TBL12DIASjLqcl9h7jD9LOFKEm6MX0YL4uFa3ZRJ9zdou9dio9Hf yjPJv+yTFjV3W7mzydQc7pvkyTSRpHPbxN/B7yySagzB5PPMbrhebLGJoNTBSrtFaidS 4Zax/qtOoj/GRnNf9srmtq8IQS4Np1EKJWn+uiKTxDBj2IPU3p2ng8ufkW8cKehHVJFR A7DOm9v26JZq3NRpNt8ct7yuSsOp8Nwqwe49p9703FvoePXvu6on2GZwiNTlD6fcJjf5 /wtwHpMqu8YVZ0Ehx0GXNgqDtpsINrmgIAil9dPfdTF7VtJiIIq9x9sm6yAPzUtTQTBw 9gUA== MIME-Version: 1.0 X-Received: by 10.140.26.243 with SMTP id 106mr11307188qgv.91.1398636388049; Sun, 27 Apr 2014 15:06:28 -0700 (PDT) Received: by 10.224.131.198 with HTTP; Sun, 27 Apr 2014 15:06:28 -0700 (PDT) Date: Mon, 28 Apr 2014 00:06:28 +0200 Message-ID: Subject: heeei From: MY NAME HERE To: MY EMAIL HERE Content-Type: multipart/alternative; boundary=001a11c00c9814689304f80d6998

--001a11c00c9814689304f80d6998 Content-Type: text/plain; charset=UTF-8

test

--001a11c00c9814689304f80d6998 Content-Type: text/html; charset=UTF-8

test

--001a11c00c9814689304f80d6998--

1
Looks like it expects the full path: /home/USERNAME/public_html/mailhandler.php, have you tried this (replacing USERNAME with your username) of course - Ohgodwhy
Yes, I have. I don't want to share my username or other data on my server. The username is correct xD - Teskon
Are you sure the path to use /usr/local/lib/php is proper? - Ohgodwhy
phpinfo says so, Ohgodwhy. See the updated file. Added the returned email I get when sending - Teskon
You should post the answer and then accept it, to help others in the future. - Ohgodwhy

1 Answers

3
votes

'Could not exec' likely means you don't have the permissions set correctly on that PHP file. You need to make sure that PHP file is executable. 755 should be good.

I realize this is an old thread but I recently did all of this and figured I'd post in case someone else ran across it.