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
https://forums.phpfreaks.com/topic/82028-solved-correct-way-of-formatting-mail/
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 =)

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.