Jump to content

[SOLVED] correct way of formatting mail


mega77

Recommended Posts

I would like to know which is the correct way of formatting a mail message.

 

$message = "text"; // should the first "$message" be with an equals sign or with a ".=" ?
$message .= "text $variable"; // is mixing text and variables inside quotes "correct" ?
$message .= "text $variable\n"; // should the "\n" be inside the quotes or outside like: $message .= "text $variable" . "\n";

 

None of these ways result in notices or errors that I know of. Even by setting php to: error_reporting(E_ALL);

Link to comment
Share on other sites

$message = "text"; // should the first "$message" be with an equals sign or with a ".=" ?
$message .= "text $variable"; // is mixing text and variables inside quotes "correct" ?
$message .= "text $variable\n"; // should the "\n" be inside the quotes or outside like: $message .= "text $variable" . "\n";

1) You're right the way you've shown it. You can't use .= as the variable $message hasn't been defined yet. .= adds to the end of a variable but it can't add to the end if nothing exists there yet => $message="text"

2) To add variables, you should use "$message .= 'text ' . $variable" Again, the . adds to the previous string, so if $variable='ruin' then $message="texttext ruin"

3) New lines should go inside the quotes, yes. So $message="texttext ruintext ruin

" =P

 

I was wrong about the second point, it seems. Look at the next post =)

Link to comment
Share on other sites

Yes it is correct.

 

1: = is an assignment operator while .= concatinates two string together. So yes, when you first create $message it only needs =

 

2: Variables can quite happilly be used within double quotes.

 

3: The \n newline char meens nothing outside of double quotes and will in fact generate an error.

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.