pipe email to php script?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

pipe email to php script?

Post by D Oliveira » 2019-08-20 16:23

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: pipe email to php script?

Post by pbottcher » 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
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: pipe email to php script?

Post by D Oliveira » 2019-08-20 18:43

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: pipe email to php script?

Post by pbottcher » 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);
?>
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: pipe email to php script?

Post by D Oliveira » 2019-08-21 00:45

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.

Post Reply