foward mail to a php script

ruicos

New Member
Messages
9
Reaction score
0
Points
0
I have been trying to foward a mail to a php script. So I pipe my mail account to the php script. The problem is what should i put in the php script to process the email?
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
You can send Mail no. of member.
PHP:
<?php
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');
mysql_select_db('mysql_dbname', $link); 

$str_query =     "select * from tablename limit 0, 10";
$recresult = mysql_query($str_query, $link);

$i    =    0;
$counter = 1;
while( $obj_row = mysql_fetch_array($recresult, MYSQL_ASSOC) )
{
    $to      = $obj_row["to_mail"];
    $subject = 'You can Subject Every Time';
    $message = 'You can change Message Every Time';
    
    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
   
    sleep(2);
}
?>

Sleep need other wise your mail sent into user Junkbox.

You can see this article
http://www.phpasks.com/articles/fowardmailtoaphpscript.html
 
Last edited:

ruicos

New Member
Messages
9
Reaction score
0
Points
0
I am using the following code in test.php :
Code:
#!/usr/bin/php -q
<?php
$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;
}
}

?>
I pipe mail in cpanel to this script . However i am getting this error :


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/ruicos/public_html/test.php
generated by test@rcosta4540.x10hosting.com

The following text was generated during the delivery attempt:

------ pipe to |/home/ruicos/public_html/test.php
generated by test@rcosta4540.x10hosting.com ------


------ This is a copy of the message, including all the headers. ------
I don't know what is wrong :S
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
Your code is right.

You can ask server administrator for mail script run or not.
 
Top