shawn77 Posted May 8, 2017 Share Posted May 8, 2017 have wrote the banner ad script for PHP7 i want to show a random banner ad in each email sent out by my whmcs but im not the very best tool in the shop when it comes to smartty php. All the codes i have seen and stuff i tried just shooting in the dark don't work. Can anybody help me with what line i would need to add in my email templates to make this work. Thanks In Advance. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 8, 2017 Share Posted May 8, 2017 it's difficult to give specific advice without seeing what the PHP code is doing, but if you wanted a pure Smarty solution (without the need for additional PHP coding), then you could add the following to one of your email templates... {$images = ['com.png','couk.png']} {assign randomindex value=$images|@array_rand} <img title="Random Image" src="http://www.domain.com/whmcs/assets/img/tld_logos/{$images.$randomindex}" alt="Random Image" border="0" /> assuming the image exists, and the path is correct, then the above should output a random image, from the array of image filenames, to the email. the important point to remember with this is that by default, you cannot use array_rand in your email templates with WHMCS v7 - you will need to modify your Smarty Security Policy to add array_rand to your modifiers array within configuration.php... // Smarty custom email based template policy: $smarty_security_policy = array( 'mail' => array( 'php_functions' => array( 'strstr', ), 'php_modifiers' => array( 'array_rand', ), ), 'system' => array( 'trusted_dir' => array( '/templates/six', ), ), ); 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted May 8, 2017 Share Posted May 8, 2017 That's very impressive Brian, will have to play around with your code myself. 0 Quote Link to comment Share on other sites More sharing options...
shawn77 Posted May 10, 2017 Author Share Posted May 10, 2017 it's difficult to give specific advice without seeing what the PHP code is doing, but if you wanted a pure Smarty solution (without the need for additional PHP coding), then you could add the following to one of your email templates... {$images = ['com.png','couk.png']} {assign randomindex value=$images|@array_rand} <img title="Random Image" src="http://www.domain.com/whmcs/assets/img/tld_logos/{$images.$randomindex}" alt="Random Image" border="0" /> assuming the image exists, and the path is correct, then the above should output a random image, from the array of image filenames, to the email. the important point to remember with this is that by default, you cannot use array_rand in your email templates with WHMCS v7 - you will need to modify your Smarty Security Policy to add array_rand to your modifiers array within configuration.php... // Smarty custom email based template policy: $smarty_security_policy = array( 'mail' => array( 'php_functions' => array( 'strstr', ), 'php_modifiers' => array( 'array_rand', ), ), 'system' => array( 'trusted_dir' => array( '/templates/six', ), ), ); here is what i have tried doing to call to the banner script.. i have tried doing a simple include <center> <? include("banners.php"); ?> </center> That dont work at all its like i never put the code in the template. I also tried doing a iframe <iframe src="https://www.easttexasbusinesssolutions.com/advertising/banners.php" height="500" width="480" border="0" scrolling="no"></iframe> on the backend where you edit the template it will pull the iframe but not the banners. I made a test account to see if it would pass the iframe off in the client email and it dont show the iframe in the welcome email even though it shows it in the backend where i put it in the welcome email template 0 Quote Link to comment Share on other sites More sharing options...
shawn77 Posted May 10, 2017 Author Share Posted May 10, 2017 oh and to add this is so i can sell banner impressions im wanting to show the banners in the Email templates.. So it not like i would just showing random photos it has to speak with the scripts DB 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 22, 2017 Share Posted May 22, 2017 here is what i have tried doing to call to the banner script..i have tried doing a simple include <center> <? include("banners.php"); ?> </center> That dont work at all its like i never put the code in the template. as a quick fix, you could wrap your code in the email template with {php}{/php} to see if it works, but that's definitely not a long-term solution. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.