Jump to content

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

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.