Reputation: 11
\I hope someone can help. I am a bit of a dunce with php but I managed to create a booking form for my bed and breakfast using a mail.php page called up from the html form.
The body goes like this:
$subject = "Booking Request";
$fields = array();
$fields{"title"} = "Title";
$fields{"name"} = "Name";
$fields{"email"} = "email";
$fields{"telephone"} = "telephone";
$fields{"mobile"} = "mobile";
$fields{"arrival_day"} = "arrival day";
$fields{"departure_day"} = "departure day";
$fields{"adults"} = "# of adults";
$fields{"children"} = "# of children";
$fields{"questions"} = "any questions?";
It works but everything comes out on one line like this
Title: Ms Name: Joe Blogs email: [email protected] telephone: 02 12345697 mobile: 01234958arrival day: 10/06/12 departure day: 20/06/12 # of adults: 8 # of children: 4 any questions?
but I want it to look like this:
Title: Ms
Name: Joe Blogs
email: [email protected]
etc.
I've tried \n
, \r
and <br/>
in all sorts of places but I'm just stabbing in the dark... can what i have be fixed or do I need to use an entirely different code?
Upvotes: 0
Views: 2077
Reputation: 1
Use nl2br();
$message = nl2br($name . " " . " wrote this:" . "\n" . $_POST['message'] . $_POST['phone'] . $_POST['email'] . "\n" . $_POST['radio']);
Upvotes: 0
Reputation: 808
I used to use "\n":
$text = 'line1\n line 2\n line 3';
The result were:
line1\n
line2\n
line3
And i was not satisfied so i found PHP_EOL
$text = 'line 1' . PHP_EOL . 'line 2' . PHP_EOL . 'line 3';
The result will be:
line 1
line 2
line 3
"<br>"
is a viable solution but you're sending "HTML" formatted email.
Upvotes: 0
Reputation: 19
You should use \n
as an end line.
And please change {}
to []
:
$fields["title"] = "Title";
$fields["name"] = "Name";
$fields["email"] = "email";
$fields["telephone"] = "telephone";
...
Upvotes: 1