Jump to content

forward fails on print_r()


rubing

Recommended Posts

Hey everyone,

 

I am piping email to a php script, which seems to be working as long as the script is simple.  However, if I call certain functions the script fails to execute properly and bounces back to the sender with the results of the function it didn't like (in this case print_r())  Here is my script:

 

#!/usr/bin/php -q
<?php
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
$lines = explode("\n", $email);
$arr_value=print_r ($lines);  //this line makes it fail  
$subject ='IT WORKS!!';
$to = '[email protected]';
mail($to, $subject, $arr_value);
?>

 

and here is the bounced message i receive:

 

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/rubing/lib/processtonight.php

    generated by [email protected]

 

The following text was generated during the delivery attempt:

 

------ pipe to |/home/rubing/lib/processtonight.php

      generated by [email protected] ------

 

Array

(

    [0] => From [email protected] Thu Mar 20 23:10:24 2008

    [1] => Received: from user-12hcspn.cable.mindspring.com ([69.22.115.55]:62111 helo=userb2bd129865)

    [2] => by richard.asmallorange.com with esmtpsa (TLSv1:RC4-MD5:128)

    [3] => (Exim 4.68)

    [4] => (envelope-from <[email protected]>)

    [5] => id 1JcXeB-0002KH-IZ

    [6] => for [email protected]; Thu, 20 Mar 2008 23:10:23 -0400

    [7] => Message-ID: <00ed01c88b01$192bd3f0$6500a8c0@userb2bd129865>

    [8] => Reply-To: <[email protected]>

    [9] => From: <[email protected]>

    [10] => To: <[email protected]>

    [11] => Subject: heeelo

    [12] => Date: Thu, 20 Mar 2008 22:10:17 -0500

    [13] => MIME-Version: 1.0

    [14] => Content-Type: multipart/alternative;

    [15] => boundary="----=_NextPart_000_00EA_01C88AD7.2E27EF70"

    [16] => X-Priority: 3

    [17] => X-MSMail-Priority: Normal

    [18] => X-Mailer: Microsoft Outlook Express 6.00.2900.3138

    [19] => X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198

    [20] =>

    [21] => This is a multi-part message in MIME format.

    [22] =>

    [23] => ------=_NextPart_000_00EA_01C88AD7.2E27EF70

    [24] => Content-Type: text/plain;

    [25] => charset="iso-8859-1"

    [26] => Content-Transfer-Encoding: quoted-printable

    [27] =>

    [28] => hhhh

    [29] => ------=_NextPart_000_00EA_01C88AD7.2E27EF70

    [30] => Content-Type: text/html;

    [31] => charset="iso-8859-1"

    [32] => Content-Transfer-Encoding: quoted-printable

    [33] =>

    [34] => <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    [35] => <HTML><HEAD>

    [36] => <META http-equiv=3DContent-Type content=3D"text/html; =

    [37] => charset=3Diso-8859-1">

    [38] => <META content=3D"MSHTML 6.00.6000.16608" name=3DGENERATOR>

    [39] => <STYLE></STYLE>

    [40] => </HEAD>

    [41] => <BODY bgColor=3D#ffffff>

    [42] => <DIV><FONT face=3DArial size=3D2>hhhh</FONT></DIV></BODY></HTML>

    [43] =>

    [44] => ------=_NextPart_000_00EA_01C88AD7.2E27EF70--

    [45] =>

    [46] =>

    [47] =>

)

 

------ This is a copy of the message, including all the headers. ------

 

Return-path: <[email protected]>

Received: from user-12hcspn.cable.mindspring.com ([69.22.115.55]:62111 helo=userb2bd129865)

by richard.asmallorange.com with esmtpsa (TLSv1:RC4-MD5:128)

(Exim 4.68)

(envelope-from <[email protected]>)

id 1JcXeB-0002KH-IZ

for [email protected]; Thu, 20 Mar 2008 23:10:23 -0400

Message-ID: <00ed01c88b01$192bd3f0$6500a8c0@userb2bd129865>

Reply-To: <[email protected]>

From: <[email protected]>

To: <[email protected]>

Subject: heeelo

Date: Thu, 20 Mar 2008 22:10:17 -0500

MIME-Version: 1.0

Content-Type: multipart/alternative;

boundary="----=_NextPart_000_00EA_01C88AD7.2E27EF70"

X-Priority: 3

X-MSMail-Priority: Normal

X-Mailer: Microsoft Outlook Express 6.00.2900.3138

X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198

 

This is a multi-part message in MIME format.

 

------=_NextPart_000_00EA_01C88AD7.2E27EF70

Content-Type: text/plain;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable

 

hhhh

------=_NextPart_000_00EA_01C88AD7.2E27EF70

Content-Type: text/html;

charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META http-equiv=3DContent-Type content=3D"text/html; =

charset=3Diso-8859-1">

<META content=3D"MSHTML 6.00.6000.16608" name=3DGENERATOR>

<STYLE></STYLE>

</HEAD>

<BODY bgColor=3D#ffffff>

<DIV><FONT face=3DArial size=3D2>hhhh</FONT></DIV></BODY></HTML>

 

------=_NextPart_000_00EA_01C88AD7.2E27EF70--

 

 

Link to comment
https://forums.phpfreaks.com/topic/97184-forward-fails-on-print_r/
Share on other sites

If you want to capture the output from the print_r() function in a variable, you need to give it a second parameter of "true":

<?php
$arr_value=print_r ($lines,true);
?>

Otherwise the output will go into the output stream and make a mess.

 

Ken

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.