mega77 Posted December 17, 2007 Share Posted December 17, 2007 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 More sharing options...
Grego Posted December 17, 2007 Share Posted December 17, 2007 $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 https://forums.phpfreaks.com/topic/82028-solved-correct-way-of-formatting-mail/#findComment-416828 Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 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 https://forums.phpfreaks.com/topic/82028-solved-correct-way-of-formatting-mail/#findComment-416829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.