0

Hey,

My code epic fails... I get delivery failed when sending an email to the email addess that pipe's to this script:

#!/usr/bin/php -q
<?php
ini_set('memory_limit', '256M'); //The concern here is having enough mem for emails with attachments.
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

// handle email

$lines = explode("\n", $email);

// empty vars

$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;

for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}



$theEmail .= $from . "\n";
$theEmail .= $subject . "\n";
$theEmail .= $headers . "\n";
$theEmail .= $message . "\n";
$theEmail .= "-------------------\n\n\n";

$file = 'email.txt';
// Get the current contents
$ccontents = file_get_contents($file);
// Append a new person to the file
$ccontents .= $theEmail;
// Write the contents back to the file
file_put_contents($file, $ccontents);
?>

Can anyone help?
Dan

3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by Danny159
0

Yes, thats all I want it to do at the min, is get the data from the email and put it in a file? Do I have to forward it on to a real mail box then?

Dan

0

Ok... I tried adding:

mail("daniel@DOMAIN.com", $subject, $message);

At the end still failed

0

It might just be the code but you should check that your web host allows this. I know that mine doesn't.

1

I am my web host ;) and I allow it :P I fixed the problem anyway thanks, I needed to CHMOD the file to 755 :)

Dan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.