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:
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--
/home/USERNAME/public_html/mailhandler.php
, have you tried this (replacing USERNAME with your username) of course - Ohgodwhy/usr/local/lib/php
is proper? - Ohgodwhy