WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] Custom Mail Template (14 posts)

  1. hempoun
    Member
    Posted 1 year ago #

    Hi

    I used subscribe2 plugin for email notifications.I have custom mailtext for sending digest mail.I used for loop for sending mail by substituting messages but i receive only one value.
    For example :
    {RESDESC}
    15 for $20 of Food and Drink During Lunch Hours Only
    {RESNAME}
    Restaurant 1
    {RESDESC}
    new deal for electronic goods
    {RESNAME}
    Restaurant 2

    Please provide me the solution to solve the issue..Thanks and Waiting for your response.

    http://wordpress.org/extend/plugins/subscribe2/

  2. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    I'd like to try and help but from the details given above I have a very limited understanding of what you are trying to do and what isn't working.

    The words you have in curly brackets {}, are not part of the Subscribe2 plugin so if you have implemented these into the code yourself then I suspect there is an issue in your code somewhere but without seeing that code I can't really say what the issue is or where.

    If you haven't written any code then your issue may be due to the fact that these keywords are not part of the Subscribe2 code.

  3. hempoun
    Member
    Posted 1 year ago #

    First of all i would like thank for your kind response.

    Actually,i have created multisite network.Each individual site has several gift certificates and every day digest mail should be sent using subscribe2 plugin.So I will have to send mail notifications to every users who have subscribed.I have a issue in sending gift cerificates from each site.What i did is, i have fetched the certificates details from my sites which has been shown below.My issue is i can't able to send multiple certificates via mail to subscribed users.

    // so get all the blog ids from the blogs table
    global $wpdb;
    $blogs = $wpdb->get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A);
    //print_r($blogs);

    // build a sql statement for each blog options table, adding in the blog id for each row
    $select_statements = array();
    foreach ($blogs as $blog_row) {
    $option_name1="wpgft_buttons";
    $option_name2="wpgft_options";
    //$select_statements[] = 'SELECT option_value, CAST( '.$blog_row['blog_id'].' AS UNSIGNED INTEGER ) AS blog_id FROM '.$wpdb->get_blog_prefix($blog_row['blog_id'])."options WHERE option_name='$option_name'";
    $select_statements[] = 'SELECT option_value FROM '.$wpdb->get_blog_prefix($blog_row['blog_id'])."options WHERE option_name='$option_name1' OR option_name='$option_name2'";

    }

    // cache the results of the union of all these select statements
    $option_results = $wpdb->get_results(implode(' UNION ALL ', $select_statements), ARRAY_A);

    //unserializing option values
    foreach($option_results as $key => $v){
    $option_results[$key]=$v['option_value'];

    $data = unserialize($option_results[$key]);
    //echo "

    ";
     //print_r($date);
    
    	$string = str_replace("{RESDESC}", html_entity_decode($data[0][description], ENT_QUOTES), $string);
    
            $string = str_replace("{RESNAME}", html_entity_decode($data[0][company], ENT_QUOTES), $string);
    
            $string = str_replace("{RESLOGO}", html_entity_decode($data[logo], ENT_QUOTES), $string);
    
    }
    
    Note : $string returns only one value while sending mail.Inside {} denotes the certificate values from db.
    
    Please help me.I'm waiting for your response.
  4. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    I have a better understanding of what you are trying to accomplish but must admit I'm still not sure I totally understand.

    However, it seems from the code snippets above that you are collecting data and storing it in atwo-dimensional array. When you call the str_replace() function you are only accessing the very first key in that array (at number 0) for the description and company. You are not then incrementing to look at record 1,2 and so on.

    I suspect you need to use a loop to cycle through the array and create a string of your data first and then call the str_replace() function so that you replace your custom keywords with a pre-formatted string that is complete.

  5. hempoun
    Member
    Posted 1 year ago #

    Can you tell me with an example so that it is easy to implement the keyword in str_replace function.

  6. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    Again, I'm not entirely clear on your code snippet but something like this perhaps:

    foreach ($data as $item) {
    	$resdesc .= html_entity_decode($data[0][description], ENT_QUOTES) . "<br />\r\n";
    	$resname .= html_entity_decode($data[0][company], ENT_QUOTES) . "<br />\r\n";
    }
    $string = str_replace("{RESDESC}", $resdesc, $string);
    $string = str_replace("{RESNAME}", $resname, $string);
  7. hempoun
    Member
    Posted 1 year ago #

    Thanks for your response.
    Still i'm getting the repeated value twice from the first array value while sending mail by using the above code snippet.Better i will explain in detail.

    For Eg:

    {RESDESC},{RESNAME} -> comes from database as

    {RESDESC}
    $15 for $20 of Food and Drink During Lunch Hours Only
    {RESNAME}
    Gift Cert1

    {RESDESC}
    new deal for electronic goods
    {RESNAME}
    Gift Cert2

    {RESDESC}
    5% discount on t-shirts
    {RESNAME}
    Gift Cert3

    The values retrieves from database is working fine.My question is while
    sending mail i will substitute the above messages like this ie {RESDESC}
    {RESNAME} in editor.On receiving mail i'm getting the first value which i mentioned above.I'm not getting all the values while sending mail.Did i need to modify the mail function? because the values from db is displaying fine but while on sending mails the bug occured.I think now you be clear with better explanation.

  8. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    Sorry, a glitch in the code I posted, it should be like this:

    foreach ($data as $item) {
    	$resdesc .= html_entity_decode($item[description], ENT_QUOTES) . "<br />\r\n";
    	$resname .= html_entity_decode($item[company], ENT_QUOTES) . "<br />\r\n";
    }
    $string = str_replace("{RESDESC}", $resdesc, $string);
    $string = str_replace("{RESNAME}", $resname, $string);
  9. hempoun
    Member
    Posted 1 year ago #

    I checked with the above code it indicates the error report as

    Fatal error: Cannot use string offset as an array in subscribe2/classes/class-s2-core.php on line 208.
    The $item[description] displays the single dimensional array value.The array value will be in two dimensional array.
    For Eg : $item[0][description];

    Array
    (
    [0] => Array
    (
    [description] => $15 for $20 of Food and Drink During Lunch Hours Only
    [company] => Company1
    )
    )
    Array
    (
    [0] => Array
    (
    [description] => new deal for electronic goods
    [company] => Company2
    )

    )

  10. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    You will need to adjust the array address within the html_entity_decode() function call to fit with your array structure then. Based on what you posted above it might be $item[0][0][description].

  11. hempoun
    Member
    Posted 1 year ago #

    I have done multiple ways to solve this issue,but still no use.While sending mail it retrieves only one value.Can you guide me in any other way?

    Thanks

  12. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    I'm still aiming pretty blind here but looking again through all of your posts I think there may be an issue in your data collection that means my suggested approach won't work.

    You posts your array structure here. But to my mind it should look more like this:

    array(2) {
    [0]=>
    array(2) {
    ["description"]=>
    string(53) "$15 for $20 of Food and Drink During Lunch Hours Only"
    ["company"]=>
    string(8) "Company1"
    }
    [1]=>
    array(2) {
    ["description"]=>
    string(29) "new deal for electronic goods"
    ["company"]=>
    string(8) "Company2"
    }
    }

    Note that you have a key zero and a key one so that the loop I suggested will work. If you collect the data into different arrays as you seem to be doing (or perhaps you update the array in a loop) then you will need multiple instances of the Keyword for it to work but how many?

  13. hempoun
    Member
    Posted 1 year ago #

    It is a multisite network so the array values will be in dynamic,i can't say the extract values from the database.When i print the array values it display the loop values but not in mail.

  14. mattyrob
    Member
    Plugin Author

    Posted 1 year ago #

    @hempoun,

    Your loop statements don't appear to be correct though and that is the issue.

    Essentially I think you are looping through your blogs but calling the replace function within this loop so the very first time the loop is called the keyword is replaced with your first database strings, the second time the loop cycles around the keyword is already replaced and therefore cannot be replaced again.

    I've suggested above that in the loop you create a string with each of the database strings added to the end but then noticed that your database collect is not one array but many, this means your original loop may be within another larger loop.

    If you cannot get this working perhaps you should consider getting some paid help. Try WP Jobs if you want to pursue that.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.