It is required to create a universal layout of html letters for automatic mailings of online stores. Such a letter will be sent to the user who placed an order through the basket. On one CMS there are several online stores, which, of course, have an individual design. The letter will be universal for all stores with the programming of the replacement of individual items. Here's how to insert variable elements in the letter?

Ie in the letter is sent "Hello, {name} enter image description here

  • right :)) 0 - L. Vadim
  • I understand that php should be used here, but I have never with it, but now I need it very badly (code example: - Julia Maksimenko
  • <table border = "1" cellpadding = "0" cellspacing = "0" valign = "top"; height = "100%" width = "550" align = "center"> <tr> <td width = "160px" height = "60px"> <img src = "ipg / barcode.png"> </ td> < td width = "160px" height = "60px"> Hello, {name} </ td> <td rowspan = "2" width = "120px"> <img src = "logo.php? id = asdfgh" width = " 120px "height =" 120px "/> </ td> </ tr> <tr> <td> </ td> </ tr> </ table> - Julia Maximenko

1 answer 1

It is possible so, using str_replace

 $fileemail = file_get_contents('email.html'); $name="John"; $number=1312321; $data = "12/01/17"; // добавляете в массив все ваши варианты $fileemail = str_replace( array('{name}','{number}','{data}'), array($name,$number,$data), $fileemail); echo $fileemail ; 

Version on the site, working

 <?php // присваивает <body text='black'> $fileemail = file_get_contents('email.html'); $name="John"; $number=1312321; $data = "12/01/17"; $art =1142; $picture="./logo.jpg"; $Name_of_product ="Беговел РТ"; $quantity=2; $price=2013; $sum=2013; $total=2013; // добавляете в массив все ваши варианты $fileemail = str_replace( array('{name}','{number}','{data}','{art}','{picture}','{Name of product}','{quantity}','{price}','{sum}','{total}'), array($name,$number,$data,$art,$picture,$Name_of_product,$quantity,$price,$sum,$total), $fileemail); echo $fileemail ; ?> 
  • tell me how to display this variable in the body of the letter <td width = "160px" height = "60px"> <p> Hello </ p>. $ name </ td> - Julia Maximenko
  • if this is an html file, then it should support php. use auto replace {name}. it works in my example - L. Vadim
  • below I inserted a clipping from the letter itself, <? php .....?> not? inserted into <head> <style>? and the output line must be <td> The order is successfully completed, {name} </ td> - Yuliya Maksimenko
  • You upload the html file in php, make changes to the file, and send it. for this you need a separate php script, a handler that will process and send email - L. Vadim
  • I didn’t understand anything (do I write <a> Good afternoon in logo in html, logo.php? {name}. </a> or just <a> Good afternoon, {name}. </a> - Julia Maximenko