-1

I'm receiving some information from the AJAX form, and I need to generate a HTML email that will use some information from this form.

For example, I want to send something basic like

$msg = '<html><body>
     <p>Bla-bla-bla $information</p></body></html>'

How can I insert $information variable into paragraph without concatenation (using it is pretty painful, as the email HTML has pretty complex structure)?

WhilseySoon
  • 322
  • 4
  • 14

2 Answers2

2

If you want to add vars into variable without concat then maybe you are looking for something like this

$information = "Info";
$msg = "<html><body>
 <p>Bla-bla-bla $information</p></body></html>";

use your double quotes Be aware if your var $information is array like this:

$information['info'] = "Info";
$information['id_info'] = 1;
$msg = "<html><body>
 <p>Bla-bla-bla $information[info]</p>
 <a href\"somepage.php?id=$information[id_info]\">Link</a></body></html>";

Double and single quotes

$email = 'someone@example.com';
$var = 'My email is $email'; // My email is $email
$var = "My email is $email"; // My email is someone@example.com
Standej
  • 749
  • 1
  • 4
  • 11
  • I like more like this to avoid unnecessary quotes :) – Standej Dec 03 '15 at 18:50
  • Thanks. Why would they ever make single and double quotes work different ways? – WhilseySoon Dec 03 '15 at 18:55
  • Oh there is lots of questions on stackoverflow about difference of quotes and you can find better answer there and more detailed then I can explain but in general in edit short difference. – Standej Dec 03 '15 at 18:59
1

There are diffent ways to do it:

1) You can use "."

For example:

$msg = '<html><body>
 <p>Bla-bla-bla'. $information.'</p></body></html>';

2) You can use double quotes:

 $msg = "<html><body>
 <p>Bla-bla-bla $information</p></body></html>";
BARIS KURT
  • 477
  • 4
  • 15