p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: String Replacement and email


Message #1 by AnthonyBol@a... on Tue, 19 Feb 2002 22:14:26 EST
Thanks for your help.  I was able to get the information from PHP.net:



$txt = preg_replace("/(\015\012)|(\015)|(\012)/","<br

/>",$txt);



Now for the tough question.  The form that is filled out is to be emailed to someone after it is displayed on a web page.  The user
clicks a "Send" button to send the email after he verifies it is the correct information.  



I put the data from the form in an <INPUT TYPE = "hidden" form fields hoping that it would pass the data to a third page,
"mail.php."  Then mail.php would put send the email using mail().



This is my form code:  I tested the variables and they are on the "display" page ... meaning when the form is submitted, the
information is displayed so the user can verify it AND it is filled in the "Hidden" field at the bottom of the page's HTML code. 
But when I submit the new form to mail.php ... the variables are empty.



*** FORM CODE ****

<FORM method="post" enctype="multipart/form-data" action="./menus/contact_us/mail.php?mail_body=<?php ">

      <INPUT TYPE="HIDDEN" name"mail_headers" value="<?php echo $mail_headers ?>">

      <INPUT TYPE="HIDDEN" name"mail_subject" value="<?php echo $mail_subject ?>">

      <INPUT TYPE="HIDDEN" name"mail_to" value="<?php echo $mail_to ?>">

      <INPUT TYPE="HIDDEN" name"mail_body" value="<?php echo $mail_body ?>">

      <INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1)" name="previous_page">

      <INPUT TYPE="SUBMIT" VALUE="Send" name="SUBMIT">

      <INPUT TYPE="button" VALUE="Home Page" onClick="window.location='index.html'" name="home_page">



This is the code on Mail.php that is supposed to send the email



*** MAIL.PHP Code *****

if($SUBMIT=="Send") {

    



    if(mail($mail_to, $mail_subject, $mail_body, $mail_headers))    {

        echo"The mail was sent";

    }else{

        echo"The mail was NOT sent";

        exit();

}

}



Again ... thanks in advance for any assistance.  I am sure there is something simple I am overlooking.



Tony





--Original Message -----

Subject: String Replacement

From: AnthonyBol@a...

Date: Sun, 17 Feb 2002 19:01:43 EST

X-Message-Number: 1



Hello,

I am trying to display text entered in a textarea field on a form in a web

page and in an email.  I did a string replace on the text data attempting to

replace the line feed or return that is in the textarea with the <BR> tag. 

Here is the code I used where $special_instructions is the name of the

textarea.  



if(!empty($special_instructions))   {

    $special_instructions = strip_tags(stripslashes($special_instructions));

    str_replace("\r\n","<br>",$special_instructions);

    $mail_body.="<br><br>$special_instructions";

}



I have used \r, \n, and \r\n as the string parameter to replace but nothing

seems to work.  Am I using the wrong characters for replacement?  Is it

different in a textarea?  Thanks in advance.



Tony



Message #2 by "Nikolai Devereaux" <yomama@u...> on Tue, 19 Feb 2002 21:25:24 -0800

Okay -- the preg_replace function works, but it was probably just shown as

en example of using that function, right?  I'd really stick to using nl2br()

since it's a lot simpler.



Anyway, on to your hard question...



I noticed that your form code has a messed up action:

  action="./menus/contact_us/mail.php?mail_body=<?php ">



Not only does it look like something's missing; I'm surprised it compiles

properly since the <?php is unterminated.



If this is only a typo, you're STILL missing the = sign between each 'name'

and the value...



FYI -- you can use shortcut notation for this stuff.  Instead of using

   <?php echo $mail_headers; ?>

you can simply type

   <?=$mail_headers;?>





anyhow, why do you pass variables with the URL _AND_ submit the form via

post?  You're probably better off sending everything via POST and making

your URL parameter another hidden input field.





nik







> -----Original Message-----

> From: AnthonyBol@a... [mailto:AnthonyBol@a...]

> Sent: Tuesday, February 19, 2002 7:14 PM

> To: beginning php

> Subject: [beginning_php] String Replacement and email

>

>

> Thanks for your help.  I was able to get the information from PHP.net:

>

> $txt = preg_replace("/(\015\012)|(\015)|(\012)/","<br

> />",$txt);

>

> Now for the tough question.  The form that is filled out is to be

> emailed to someone after it is displayed on a web page.  The user

> clicks a "Send" button to send the email after he verifies it is

> the correct information.

>

> I put the data from the form in an <INPUT TYPE = "hidden" form

> fields hoping that it would pass the data to a third page,

> "mail.php."  Then mail.php would put send the email using mail().

>

> This is my form code:  I tested the variables and they are on the

> "display" page ... meaning when the form is submitted, the

> information is displayed so the user can verify it AND it is

> filled in the "Hidden" field at the bottom of the page's HTML

> code.  But when I submit the new form to mail.php ... the

> variables are empty.

>

> *** FORM CODE ****

> <FORM method="post" enctype="multipart/form-data"

> action="./menus/contact_us/mail.php?mail_body=<?php ">

>       <INPUT TYPE="HIDDEN" name"mail_headers" value="<?php echo

> $mail_headers ?>">

>       <INPUT TYPE="HIDDEN" name"mail_subject" value="<?php echo

> $mail_subject ?>">

>       <INPUT TYPE="HIDDEN" name"mail_to" value="<?php echo $mail_to ?>">

>       <INPUT TYPE="HIDDEN" name"mail_body" value="<?php echo

> $mail_body ?>">

>       <INPUT TYPE="button" VALUE="Previous Page"

> onClick="history.go(-1)" name="previous_page">

>       <INPUT TYPE="SUBMIT" VALUE="Send" name="SUBMIT">

>       <INPUT TYPE="button" VALUE="Home Page"

> onClick="window.location='index.html'" name="home_page">

>

> This is the code on Mail.php that is supposed to send the email

>

> *** MAIL.PHP Code *****

> if($SUBMIT=="Send") {

>

>

>     if(mail($mail_to, $mail_subject, $mail_body, $mail_headers))    {

>         echo"The mail was sent";

>     }else{

>         echo"The mail was NOT sent";

>         exit();

> }

> }

>

> Again ... thanks in advance for any assistance.  I am sure there

> is something simple I am overlooking.

>

> Tony

>

>

> --Original Message -----

> Subject: String Replacement

> From: AnthonyBol@a...

> Date: Sun, 17 Feb 2002 19:01:43 EST

> X-Message-Number: 1

>

> Hello,

> I am trying to display text entered in a textarea field on a form in a web

> page and in an email.  I did a string replace on the text data

> attempting to

> replace the line feed or return that is in the textarea with the

> <BR> tag.

> Here is the code I used where $special_instructions is the name of the

> textarea.

>

> if(!empty($special_instructions))   {

>     $special_instructions 

> strip_tags(stripslashes($special_instructions));

>     str_replace("\r\n","<br>",$special_instructions);

>     $mail_body.="<br><br>$special_instructions";

> }

>

> I have used \r, \n, and \r\n as the string parameter to replace

> but nothing

> seems to work.  Am I using the wrong characters for replacement?  Is it

> different in a textarea?  Thanks in advance.

>

> Tony

>

>




> $subst('Email.Unsub').



Message #3 by AnthonyBol@a... on Wed, 20 Feb 2002 19:19:31 EST
Hi!

I did use nl2br() but it didn't work.  I am running PHP 4.0.4 and I believe that nl2br() is for 4.0.5.  Is that correct?



You are correct.  The unterminated <?php is a typo and I am not trying to pass the data via the URL.  I sent the email before I
realized I had that leftover code from the trouble shooting attempts I made.  I have made the corrections below.  



I created a simple php page on which I only typed



if(empty($mail_body)     {

echo("There is nothing in the variable");

}else{

echo "$mail_body";

}



It returned "There is nothing in the variable" each time.  But if I use a simple HTML form and passed it to that php page, it
displayed the $mail_body value.



Any ideas?



Thanks again,

Tony







----------------------------------------------------------------------



Subject: String Replacement and email

From: AnthonyBol@a...

Date: Tue, 19 Feb 2002 22:14:26 EST

X-Message-Number: 2



Thanks for your help.  I was able to get the information from PHP.net:



$txt = preg_replace("/(\015\012)|(\015)|(\012)/","<br

/>",$txt);



Now for the tough question.  The form that is filled out is to be emailed to

someone after it is displayed on a web page.  The user clicks a "Send" button

to send the email after he verifies it is the correct information.  



I put the data from the form in an <INPUT TYPE = "hidden" form fields hoping

that it would pass the data to a third page, "mail.php."  Then mail.php would

put send the email using mail().



This is my form code:  I tested the variables and they are on the "display"

page ... meaning when the form is submitted, the information is displayed so

the user can verify it AND it is filled in the "Hidden" field at the bottom

of the page's HTML code.  But when I submit the new form to mail.php ... the

variables are empty.



*** FORM CODE ****

<FORM method="post" enctype="multipart/form-data"

action="./menus/contact_us/mail.php">

      <INPUT TYPE="HIDDEN" name"mail_headers" value="<?php echo $mail_headers

?>">

      <INPUT TYPE="HIDDEN" name"mail_subject" value="<?php echo $mail_subject

?>">

      <INPUT TYPE="HIDDEN" name"mail_to" value="<?php echo $mail_to ?>">

      <INPUT TYPE="HIDDEN" name"mail_body" value="<?php echo $mail_body ?>">

      <INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1)"

name="previous_page">

      <INPUT TYPE="SUBMIT" VALUE="Send" name="SUBMIT">

      <INPUT TYPE="button" VALUE="Home Page"

onClick="window.location='index.html'" name="home_page">



This is the code on Mail.php that is supposed to send the email



*** MAIL.PHP Code *****

if($SUBMIT=="Send") {

    



    if(mail($mail_to, $mail_subject, $mail_body, $mail_headers))    {

        echo"The mail was sent";

    }else{

        echo"The mail was NOT sent";

        exit();

}

}



Again ... thanks in advance for any assistance.  I am sure there is something

simple I am overlooking.



Tony



Message #4 by "Nikolai Devereaux" <yomama@u...> on Wed, 20 Feb 2002 16:26:07 -0800

I dunno.. I think it might be because you have input type=button within the

form...  have you tried moving the buttons to outside of the form?







> -----Original Message-----

> From: AnthonyBol@a... [mailto:AnthonyBol@a...]

> Sent: Wednesday, February 20, 2002 4:20 PM

> To: beginning php

> Subject: [beginning_php] Re: String Replacement and Email

>

>

> Hi!

> I did use nl2br() but it didn't work.  I am running PHP 4.0.4 and

> I believe that nl2br() is for 4.0.5.  Is that correct?

>

> You are correct.  The unterminated <?php is a typo and I am not

> trying to pass the data via the URL.  I sent the email before I

> realized I had that leftover code from the trouble shooting

> attempts I made.  I have made the corrections below.

>

> I created a simple php page on which I only typed

>

> if(empty($mail_body)     {

> echo("There is nothing in the variable");

> }else{

> echo "$mail_body";

> }

>

> It returned "There is nothing in the variable" each time.  But if

> I use a simple HTML form and passed it to that php page, it

> displayed the $mail_body value.

>

> Any ideas?

>

> Thanks again,

> Tony

>

>

>

> ----------------------------------------------------------------------

>

> Subject: String Replacement and email

> From: AnthonyBol@a...

> Date: Tue, 19 Feb 2002 22:14:26 EST

> X-Message-Number: 2

>

> Thanks for your help.  I was able to get the information from PHP.net:

>

> $txt = preg_replace("/(\015\012)|(\015)|(\012)/","<br

> />",$txt);

>

> Now for the tough question.  The form that is filled out is to be

> emailed to

> someone after it is displayed on a web page.  The user clicks a

> "Send" button

> to send the email after he verifies it is the correct information.

>

> I put the data from the form in an <INPUT TYPE = "hidden" form

> fields hoping

> that it would pass the data to a third page, "mail.php."  Then

> mail.php would

> put send the email using mail().

>

> This is my form code:  I tested the variables and they are on the

> "display"

> page ... meaning when the form is submitted, the information is

> displayed so

> the user can verify it AND it is filled in the "Hidden" field at

> the bottom

> of the page's HTML code.  But when I submit the new form to

> mail.php ... the

> variables are empty.

>

> *** FORM CODE ****

> <FORM method="post" enctype="multipart/form-data"

> action="./menus/contact_us/mail.php">

>       <INPUT TYPE="HIDDEN" name"mail_headers" value="<?php echo

> $mail_headers

> ?>">

>       <INPUT TYPE="HIDDEN" name"mail_subject" value="<?php echo

> $mail_subject

> ?>">

>       <INPUT TYPE="HIDDEN" name"mail_to" value="<?php echo $mail_to ?>">

>       <INPUT TYPE="HIDDEN" name"mail_body" value="<?php echo

> $mail_body ?>">

>       <INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1)"

> name="previous_page">

>       <INPUT TYPE="SUBMIT" VALUE="Send" name="SUBMIT">

>       <INPUT TYPE="button" VALUE="Home Page"

> onClick="window.location='index.html'" name="home_page">

>

> This is the code on Mail.php that is supposed to send the email

>

> *** MAIL.PHP Code *****

> if($SUBMIT=="Send") {

>

>

>     if(mail($mail_to, $mail_subject, $mail_body, $mail_headers))    {

>         echo"The mail was sent";

>     }else{

>         echo"The mail was NOT sent";

>         exit();

> }

> }

>

> Again ... thanks in advance for any assistance.  I am sure there

> is something

> simple I am overlooking.

>

> Tony

>

>




> $subst('Email.Unsub').



Message #5 by "Lawrence" <lkrubner@g...> on Thu, 21 Feb 2002 00:08:07 -0500

> Hi!

> I did use nl2br() but it didn't work.  I am running PHP 4.0.4 and I believe that nl2br() is for

4.0.5.  Is that correct?



My first reaction was that register_globals was off, though it should be on by default in version

4.0.4. However, as a security measure, someone may have turned it off. What do you get when you run

php_info ?





























>

> You are correct.  The unterminated <?php is a typo and I am not trying to pass the data via the

URL.  I sent the email before I realized I had that leftover code from the trouble shooting attempts

I made.  I have made the corrections below.

>

> I created a simple php page on which I only typed

>

> if(empty($mail_body)     {

> echo("There is nothing in the variable");

> }else{

> echo "$mail_body";

> }

>

> It returned "There is nothing in the variable" each time.  But if I use a simple HTML form and

passed it to that php page, it displayed the $mail_body value.

>

> Any ideas?

>

> Thanks again,

> Tony

>

>

>

> ----------------------------------------------------------------------

>

> Subject: String Replacement and email

> From: AnthonyBol@a...

> Date: Tue, 19 Feb 2002 22:14:26 EST

> X-Message-Number: 2

>

> Thanks for your help.  I was able to get the information from PHP.net:

>

> $txt = preg_replace("/(\015\012)|(\015)|(\012)/","<br

> />",$txt);

>

> Now for the tough question.  The form that is filled out is to be emailed to

> someone after it is displayed on a web page.  The user clicks a "Send" button

> to send the email after he verifies it is the correct information.

>

> I put the data from the form in an <INPUT TYPE = "hidden" form fields hoping

> that it would pass the data to a third page, "mail.php."  Then mail.php would

> put send the email using mail().

>

> This is my form code:  I tested the variables and they are on the "display"

> page ... meaning when the form is submitted, the information is displayed so

> the user can verify it AND it is filled in the "Hidden" field at the bottom

> of the page's HTML code.  But when I submit the new form to mail.php ... the

> variables are empty.

>

> *** FORM CODE ****

> <FORM method="post" enctype="multipart/form-data"

> action="./menus/contact_us/mail.php">

>       <INPUT TYPE="HIDDEN" name"mail_headers" value="<?php echo $mail_headers

> ?>">

>       <INPUT TYPE="HIDDEN" name"mail_subject" value="<?php echo $mail_subject

> ?>">

>       <INPUT TYPE="HIDDEN" name"mail_to" value="<?php echo $mail_to ?>">

>       <INPUT TYPE="HIDDEN" name"mail_body" value="<?php echo $mail_body ?>">

>       <INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1)"

> name="previous_page">

>       <INPUT TYPE="SUBMIT" VALUE="Send" name="SUBMIT">

>       <INPUT TYPE="button" VALUE="Home Page"

> onClick="window.location='index.html'" name="home_page">

>

> This is the code on Mail.php that is supposed to send the email

>

> *** MAIL.PHP Code *****

> if($SUBMIT=="Send") {

>

>

>     if(mail($mail_to, $mail_subject, $mail_body, $mail_headers))    {

>         echo"The mail was sent";

>     }else{

>         echo"The mail was NOT sent";

>         exit();

> }

> }

>

> Again ... thanks in advance for any assistance.  I am sure there is something

> simple I am overlooking.

>

> Tony

>

>







  Return to Index