Search code examples
phpemail-client

Pass and display dynamic array in tectite form mail template


I am using Tectite Form mail to send emails in my project . The templates being used are files like example1.email.html . I need to pass a dynamic array in the mail options from the PHP script to this template and then parse the array and show both the keys and values of the array in the template . How can I achieve this using Tectite Form mail . If this cannot be done using Tectite ,then request you to suggest some suitable email software


Solution

  • Add in your template $dynamicarray

    <html>
    <body>
        //other html
        $dynamicarray
    </body>
    </html>
    

    Your dynamic array

    $dynamicArray = array(
        "Peter"=>"35",
        "Ben"=>"37",
        "Joe"=>"43"
    );
    

    Generate dynamic html using array

    $arrayHtml = "";
    foreach($dynamicArray as $key=>$value) {
        $arrayHtml.="<p>".$key. " : ".$value."</p>";
    }
    

    Pass in data. which is used in while making API request

    $data = "mail_options=".urlencode('FromAddr=xyz.com, HTMLTemplate=templateName.html').
    "&dynamicarray=".urlencode($arrayHtml);
    
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);