Page 1 of 1
pipe email to php script?
Posted: 2019-08-20 16:23
by D Oliveira
Can any of you gurus save me?
ajax-pipe.php
Code: Select all
#!/usr/local/bin/php -q
<? php
$fd = fopen("php://stdin", "r");
$email_content = "";
while (!feof($fd)) {
$email_content .= fread($fd, 1024);
}
fclose($fd);
//split the string into array of strings, each of the string represents a single line, received
$lines = explode("\n", $email_content);
// initialize variable which will assigned later on
$from = "";
$subject = "";
$headers = "";
$message = "";
$is_header= true;
//loop through each line
for ($i=0; $i < count($lines); $i++) {
if ($is_header) {
// hear information. instead of main message body, all other information are here.
$headers .= $lines[$i]."\n";
// Split out the subject portion
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
//Split out the sender information portion
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// content/main message body information
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$is_header = false;
}
}
$currDir = dirname(__FILE__);
include("{$currDir}/defaultLang.php");
include("{$currDir}/language.php");
include("{$currDir}/lib.php");
include_once("{$currDir}/header.php");
$adminConfig = config('adminConfig');
sql("INSERT INTO `treinocardio` set neutral_field='testeee', neutral_field2=$subject", $eo);
?>
cpanel config
https://i.imgur.com/iB9RMqA.png
Re: pipe email to php script?
Posted: 2019-08-20 17:18
by pbottcher
Hi,
what is your issue?
In your file you have a blank before php,
<? php
maybe you need to change it to
<?php
Re: pipe email to php script?
Posted: 2019-08-20 18:43
by D Oliveira
pböttcher wrote: ↑2019-08-20 17:18
Hi,
what is your issue?
In your file you have a blank before php,
<? php
maybe you need to change it to
<?php
Thank you for replying, my issue is that i have no way of generating a log to check why it isn't working, fixed the <?php and still no progress, this is a convenient way to keep the user's access to the app, theres a wordpress plugin that deploys an email when user failed to pay subscription, so my thought process was to shoot a duplicate email to my main cpanel email so that i could pipe the users email, fetch it from the db and disable user's access, this script was a first attempt but unsuccessfull unfortunately, can you provide a path? thanks again
Re: pipe email to php script?
Posted: 2019-08-20 20:24
by pbottcher
Hi,
can you check your settings on your php file. The file needs to have unix line endings.
Can you check the php path.
The php file needs to have the rights 755.
I tried this in my environment and this worked just fine (needed to remove the appgini settings as I do not have appgini running in that environment).
Code: Select all
#!/usr/bin/php -q
<?php
$fd = fopen("php://stdin", "r");
$email_content = "";
while (!feof($fd)) {
$email_content .= fread($fd, 1024);
}
fclose($fd);
//split the string into array of strings, each of the string represents a single line, received
$lines = explode("\n", $email_content);
// initialize variable which will assigned later on
$from = "";
$subject = "";
$headers = "";
$message = "";
$is_header= true;
//loop through each line
for ($i=0; $i < count($lines); $i++) {
if ($is_header) {
// hear information. instead of main message body, all other information are here.
$headers .= $lines[$i]."\n";
// Split out the subject portion
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
//Split out the sender information portion
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// content/main message body information
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$is_header = false;
}
}
$currDir = dirname(__FILE__);
// include("{$currDir}/defaultLang.php");
// include("{$currDir}/language.php");
// include("{$currDir}/lib.php");
// include_once("{$currDir}/header.php");
// $adminConfig = config('adminConfig');
$fp=fopen("trace.txt","w");
$message = "sql(\"INSERT INTO `treinocardio` set neutral_field='testeee', neutral_field2=".$subject."\", $eo)";
fwrite($fp, $currDir);
fwrite($fp, $message);
fclose($fp);
?>
Re: pipe email to php script?
Posted: 2019-08-21 00:45
by D Oliveira
pböttcher wrote: ↑2019-08-20 20:24
Hi,
can you check your settings on your php file. The file needs to have unix line endings.
Can you check the php path.
The php file needs to have the rights 755.
I tried this in my environment and this worked just fine (needed to remove the appgini settings as I do not have appgini running in that environment).
Code: Select all
#!/usr/bin/php -q
<?php
$fd = fopen("php://stdin", "r");
$email_content = "";
while (!feof($fd)) {
$email_content .= fread($fd, 1024);
}
fclose($fd);
//split the string into array of strings, each of the string represents a single line, received
$lines = explode("\n", $email_content);
// initialize variable which will assigned later on
$from = "";
$subject = "";
$headers = "";
$message = "";
$is_header= true;
//loop through each line
for ($i=0; $i < count($lines); $i++) {
if ($is_header) {
// hear information. instead of main message body, all other information are here.
$headers .= $lines[$i]."\n";
// Split out the subject portion
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
//Split out the sender information portion
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// content/main message body information
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$is_header = false;
}
}
$currDir = dirname(__FILE__);
// include("{$currDir}/defaultLang.php");
// include("{$currDir}/language.php");
// include("{$currDir}/lib.php");
// include_once("{$currDir}/header.php");
// $adminConfig = config('adminConfig');
$fp=fopen("trace.txt","w");
$message = "sql(\"INSERT INTO `treinocardio` set neutral_field='testeee', neutral_field2=".$subject."\", $eo)";
fwrite($fp, $currDir);
fwrite($fp, $message);
fclose($fp);
?>
Im having a bunch of problems with godaddy messing with my MX records, ill have to wait 48 hours to test this code, im sorry for the delay, really appreciate your input and thank you for the insightful solution.