Jump to content

Please help echoing a variable


lingo5

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/253900-please-help-echoing-a-variable/
Share on other sites

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?

 

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"

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

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.