Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

add line break in the email result of a form

Featured Replies

Hi,

I don't know much of php and i have a form on my website that, for now, sends its content like this:

"

topic of the text-area : content of the text area

"

i would like the mail to look more like this:

 

"

topic of the text-area:

content of the text area

"

 

and i think the code part is this one :

 

if ($mField->type == '1') {
   print '<textarea class="rapid_contact_ex textarea ' . $mod_class_suffix . '" name="'.$form_id.'rpx_'.$field_name.'" cols="' . $t_cols . '" rows="' . $t_rows . '">';
   if (isset($_POST[$form_id."rpx_".$field_name])) {
 print $_POST[$form_id."rpx_".$field_name];
   }
   else {
 print JText::_($mField->default);
   }
   print '</textarea>'."\n";
 }

 

i played with "\n" or nl2br() but in vain, i can't manage to get what i want.

could you please help me with this?

 

thanks a lot !

Windows server? Give \r\n a go instead of \n.

 

eg:

 

first line\r\nsecond line

 

should produce...

 

first line

second line

 

On *nix servers \n should so the job.

  • Author

and how do i check which is first line and which is second? i know i didn't give much code, but i'm really not into php... i can give more code if you want me to?

Your topic title says email so look for the mail function which could look something like this:-

mail( $admin, "Feedback: $subject", "$name\r\n$email\r\n$message\r\n$component $size\r\n$delivery\r\n$confirmation", "From: $name <$admin>" );

where the \r\n should make a line break.

Nope, $_POST is a special variable which holds any data posted to the page, it's unrelated to the mail() function (in fact it's not even a function!).

 

The mail() function works like this:

 

$to = "myaddress@mydomain.com";
$subject = "automatic email from my website";
$message = "This is the first line of the email body, \r\n this is the second line.";
mail( $to , $subject , $message );

 

There's more to it than that, you need to check for tampered headers and so on if there's any user input going on. Oh, and to keep your server admin/owner happy please don't call it mailform.php ! There are lots of automated bots that trawl through websites looking for mailform.php and similar names, and then scanning them for vulnerabilities. A surprising amount of spam is sent through this route.

Actually, my reference to the mail function may be misleading. Are you extracting from a database to display in rows in the email and want items from one database field to be displayed with a line break? That may need different help and perhaps the database entry needs a line break inserted in the field, or are "topic of the text-area:" and "content of the text area" in separate dabase fields?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.