Jump to content

Help with script receiving email


deived

Recommended Posts

I'm working on a script where I can send an sms text message to an email address on my domain (through my providers gateway) and pipe that to a PHP script, where I'll parse it and add to a MySQL database.  It seems to be working, but the problem that I'm having is that when I send the text message, I get a delivery failure message saying that it could not be forwarded to the following address, and shows the path to my script.  The message does actually show up on the script and it gets added to the database as it should.  I get the same message when I send to that email from my personal yahoo email account.

 

Can anyone tell me why I'm getting that failure response when the message does go through?

I hope this makes sense and that someone can help.

Link to comment
https://forums.phpfreaks.com/topic/177000-help-with-script-receiving-email/
Share on other sites

If it helps, here's my code.  Im not sure if its a PHP problem or a mail problem.

Right now its just setup to output to a text file.

#!/usr/bin/php -q
<?php

$handle = fopen('php://stdin', 'r');
$content = '';
while (!feof($handle))
$content .= fread($handle, 1024);
fclose($handle);

$fullText = $content;

$lines = explode("\n", $fullText);
$inMsg = false;
//$this->message = '';

for ($i=0;$i<sizeof($lines);$i++)
{
if (!$inMsg)
{
	//$this->headers['all'][] = $lines[$i];
	if (preg_match("/^Subject: (.*)/", $lines[$i], $matches))
		$headers['subject'] = $matches[1];
	if (preg_match("/^From: (.*)/", $lines[$i], $matches))
		$headers['from'] = $matches[1];
}
else
	$message .= $lines[$i] . "\n";

if (trim($lines[$i]) == '')
	$inMsg = true;
}



$filename = "sms.txt";
$fp = fopen($filename,'a') or die("File didn't work!");
flock($fp, LOCK_EX);

fwrite($fp,"MESSAGE INFO\n");

fwrite($fp, "MESSAGE INFO: \n$message\n");

fwrite($fp,"HEADER INFO\n");

foreach ($headers as $name => $data)
{
fwrite($fp, "Header Name: $name  ||  Header Value: $data\n");

}
fwrite($fp,"COMPLETE EMAIL---\n");
for ($x=0;$x<sizeof($lines);$x++)
{
fwrite($fp,"$x $lines[$x]");
}


flock($fp, LOCK_UN);
fclose($fp);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.