SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
Thread: Putting in line breaks
Hybrid View
-
May 15, 2009, 06:32 #1
- Join Date
- Jun 2006
- Location
- Australia
- Posts
- 189
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Putting in line breaks
Gudday all
I have a long string called $message. Currently it places all the text on a single line.
PHP Code:<?php
...
$message = "I would a copy of the Petals & Patches catalogue send to me please -
Media: $media
Name: $name
Address: $address
City/Town: $city
State: $state
Post code: $postcode
Country: $country
E-mail: $email"
....
?>
I would a copy of the Petals & Patches catalogue send to me please -
Media: $media
Name: $name
Address: $address
City/Town: $city
State: $state
..
What would I need to do to the PHP code to achieve this?========================
Carn the Tiges!
www.petalsandpatches.com
-
May 15, 2009, 06:42 #2
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Heredoc syntax.
PHP Code:$message = <<<TEXT
I would a copy of the Petals & Patches catalogue send to me please -
Media: $media
Name: $name
Address: $address
City/Town: $city
State: $state
TEXT;
Pawel Decowski (you should follow me on Twitter)
-
May 15, 2009, 06:56 #3
-
May 15, 2009, 07:04 #4
- Join Date
- Jun 2006
- Location
- Australia
- Posts
- 189
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry should have been more explicit.
An e-mail is being generated.
When those ideas still work?========================
Carn the Tiges!
www.petalsandpatches.com
-
May 15, 2009, 07:04 #5
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Last edited by decowski; May 15, 2009 at 08:32.
Pawel Decowski (you should follow me on Twitter)
-
May 15, 2009, 07:51 #6
Do emails require \r\n rather than just \n? If so, convert plain newlines into carriage returns with newlines.
PHP Code:$message = str_replace("\n", "\r\n", $message);
-
May 15, 2009, 07:52 #7
-
May 16, 2009, 04:50 #8
- Join Date
- Jun 2006
- Location
- Australia
- Posts
- 189
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Gents
Thanks for your help
I have tried the code you noted but are getting a parse error
"Parse error: syntax error, unexpected $end in C:\wamp\www\PetalsandPatches\cataloguetest-3.php on line 34"
Line 34 is outside the code.
I reckon the problem is the if loop but after reading the doco I am no wiser. Unless I can make use of the \r\n?
PHP Code:<?
...
if ($name != "" AND $address != "" AND $city != "" AND $state != "" AND $postcode != "")
{
$sendto = "tlknell@somewhere.com.au";
$subject = "Petals & Patches catalogue request";
$message = <<<TEXT
I would a copy of the Petals & Patches catalogue send to me please -
Media: $media
Name: $name
Address: $address
City/Town: $city
State: $state
Post code: $postcode
Country: $country
E-mail: $email";
TEXT;
// sending e-mail
mail("$sendto", "$subject", "$message");
//echo "Your message was sent";
header('Location: thankyou.htm');
exit();
}
?>========================
Carn the Tiges!
www.petalsandpatches.com
-
May 16, 2009, 04:52 #9
The line containing TEXT; needs to have no whitespace before it. The only thing that the line should contain is TEXT; - nothing more, nothing less.
-
May 16, 2009, 04:53 #10
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That error means you have an unclosed block of code (in other words a missing bracket).
Pawel Decowski (you should follow me on Twitter)
-
May 16, 2009, 05:10 #11
- Join Date
- Jun 2006
- Location
- Australia
- Posts
- 189
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Gents
Here is the full PHP code
PHP Code:<?php
$media = $_POST['media'];
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$email = $_POST['email'];
$sendto = "tlknell@tpg.com.au";
$subject = "Petals & Patches catalogue request";
$message = <<<TEXT
I would a copy of the Petals & Patches catalogue send to me please -
Media: $media
Name: $name
Address: $address
City/Town: $city
State: $state
Post code: $postcode
Country: $country
E-mail: $email";
TEXT;
// sending e-mail
mail("$sendto", "$subject", "$message");
header('Location: thankyou.htm');
exit();
?>
I am still getting a parse error.========================
Carn the Tiges!
www.petalsandpatches.com
-
May 16, 2009, 05:15 #12
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
As Salathe writes, the TEXT; line should have no whitespace before or after (except newline) and it seems you have a single space character after TEXT;.
The code does work after removing the space, as you can see.Pawel Decowski (you should follow me on Twitter)
Bookmarks