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 = 'wherever_i_want_to_send_it@example.com';
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 tonight@birminghammusiclive.com

 

The following text was generated during the delivery attempt:

 

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

      generated by tonight@birminghammusiclive.com ------

 

Array

(

    [0] => From admin@birminghammusiclive.com 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 <admin@birminghammusiclive.com>)

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

    [6] => for tonight@birminghammusiclive.com; Thu, 20 Mar 2008 23:10:23 -0400

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

    [8] => Reply-To: <admin@birminghammusiclive.com>

    [9] => From: <admin@birminghammusiclive.com>

    [10] => To: <tonight@birminghammusiclive.com>

    [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: <admin@birminghammusiclive.com>

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 <admin@birminghammusiclive.com>)

id 1JcXeB-0002KH-IZ

for tonight@birminghammusiclive.com; Thu, 20 Mar 2008 23:10:23 -0400

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

Reply-To: <admin@birminghammusiclive.com>

From: <admin@birminghammusiclive.com>

To: <tonight@birminghammusiclive.com>

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
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

Link to comment
Share on other sites

Actually, you would see the affects in web pages also, but slightly differently. Compare the output from the following snippets:

<?php
print_r(range(1,10));
?>

and

<?php
echo '<pre>' . print_r(range(1,10),true) . '</pre>';
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.