lingo5 Posted December 27, 2011 Share Posted December 27, 2011 Hi, I am trying to insert a variable in the body of an email lik so: $message = "Dear Administrator,\n\nthe following distributor\n\n'.$row_admin_login_RS['distributor_company_name'].'\n\nHas modified his Distributor information record.\n\"; I know it must be a syntax error...but I can't figure it out. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/ Share on other sites More sharing options...
ManiacDan Posted December 27, 2011 Share Posted December 27, 2011 If you open a string with double quotes, you must close it with double quotes: $message = "Dear Administrator,\n\nthe following distributor\n\n" . $row_admin_login_RS['distributor_company_name'] . "\n\nHas modified his Distributor information record.\n"; The code you posted would (probably) throw a fatal PHP parse error. Are you not showing errors? Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301622 Share on other sites More sharing options...
lingo5 Posted December 27, 2011 Author Share Posted December 27, 2011 oh...I see... I was getting a 500 error. Thanks for your help, it works great. Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301623 Share on other sites More sharing options...
lingo5 Posted December 27, 2011 Author Share Posted December 27, 2011 I have one more question about this, can I insert html code in my email?, I have tried like this: $strMessage = "<table width="450" border="0" cellspacing="0" cellpadding="4"> <tr> <td><span class="NoResultsTXT2">Dear Administrator,</span></td> </tr> <tr> <td><span class="NoResultsTXT2">the following distributor</span></td> </tr> <tr> <td><span class="precioVenta">$row_admin_login_RS['distributor_company_name']</span></td> </tr> <tr> <td><span class="NoResultsTXT2">Has modified his Distributor information record. </span></td> </tr> </table>"; But I get this error "Parse error: syntax error, unexpected T_LNUMBER in /usr/home/eu45antifoul.com/web/distributors/DIST_distributors_update.php on line 216" Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301627 Share on other sites More sharing options...
litebearer Posted December 27, 2011 Share Posted December 27, 2011 pay close attention to your placement/use of double and single quotes. You are closing stings before you are intending Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301628 Share on other sites More sharing options...
peter_anderson Posted December 27, 2011 Share Posted December 27, 2011 You will need to replace the " (speech mark) for your HTML with a \" This will escape the marks, which will get rid of this error. You'll need to do it to ALL speech marks in your email. Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301629 Share on other sites More sharing options...
lingo5 Posted December 27, 2011 Author Share Posted December 27, 2011 Thanks Peter_anderson, but by doing that styles are not applied to te email. I would like to be able to send a styled message using my own style sheet. How can I do that?... Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301631 Share on other sites More sharing options...
Pikachu2000 Posted December 27, 2011 Share Posted December 27, 2011 If I recall correctly, most email clients will need the CSS inline in order to use it, rather than in an external style sheet. Of course, you also need to make sure the mail is sent with appropriate headers for an HTML email. But that aside, you can't use the same type of quotes inside a string as the quotes that enclose the string without escaping them with a backslash. There is no exception to that. Therefore, in a double quoted string, to insert a literal double quote, you need to use \". If you'd rather avoid the hassle and confusion of that, you can use HEREDOC syntax. Details on both can be found in the manual. http://www.php.net/manual/en/language.types.string.php Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301636 Share on other sites More sharing options...
lingo5 Posted December 27, 2011 Author Share Posted December 27, 2011 thanks Pikachu, I'm loking at that. Quote Link to comment https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/#findComment-1301639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.