Problem with sending emails


Home Forums Front End PM PRO Problem with sending emails

This topic is: Resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #16139
    test programmer
    Participant

    I have problems sending emails with messages & announcements. The setting from the user to receive an email with a message or announcement is active.

    This works for messages. Only not in the language set by the user. In the templates folder (/front-end-pm-pro/templates/emails) I have the following files:

    • new_announcement_en.php
    • new_announcement_fr.php
    • new_announcement_nl.php
    • new_answer_en.php
    • new_answer_fr.php
    • new_answer_nl.php
    • new_message_en.php
    • new_message_fr.php
    • new_message_nl.php

    Is there a possibility to make this dependent on the language of the user?

    In the case of announcements, no mails are sent at all. While this is active set in backend.

    What could be the reason for this?

    #16144
    Shamim Hasan
    Keymaster

    Please follow https://www.shamimsplugins.com/docs/front-end-pm-pro/customization-front-end-pm-pro/create-own-email-template/

    Within your template conditionally include your user set language template.

    #16160
    test programmer
    Participant

    I now have the following:

    
    add_filter( 'fep_eb_email_legends', 'fep_cus_fep_email_legends', 10, 3);
    
    function fep_cus_fep_email_legends( $legends, $post, $user_email ){
    
        $user = get_user_by( 'email', $user_email );
    
        $language = get_user_meta( (int)$user->ID, 'icl_admin_language', true );
    
        $legends['receiver_language'] = array(
            'description' => __('Receiver language', 'front-end-pm'),
            'where' => array( 'newmessage', 'reply', 'announcement' ), //where this tag will be used
            'replace_with' => $language
        );
    
        return $legends;
    }
    
    add_filter( 'fep_eb_templates', 'fep_cus_fep_eb_templates', 10, 2 );
    
    function fep_cus_fep_eb_templates( $templates, $where )
    {
      $templates['new_message'] = 'Nieuw bericht';
      return $templates;
    }
    

    In my template I have the language by the added field receiver_language.

    But how can I use this in my template in an if structure?

    Is this the way I should do this?

    #16165
    Shamim Hasan
    Keymaster

    No need to create legend for that.

    Proceed in following way.

    1. register your email template

    add_filter( 'fep_eb_templates', function( $templates, $where ) {
      $templates['new_message'] = 'Nieuw bericht';
      return $templates;
    }, 10, 2 );
    

    2. Now in emails/new_message.php file use

    $language = get_user_meta( fep_get_userdata( $user_email, 'ID', 'email'), 'icl_admin_language', true );
    
    if( 'fr' == $language ){
        require( fep_locate_template( 'emails/new_message_fr.php' ) );
    }
    

    Let me know.

    #16169
    test programmer
    Participant

    Thank you! Works perfect! Do you also know how I can change the subject of the mail? So it’s translated?

    #16183
    Shamim Hasan
    Keymaster

    Please use fep_filter_before_email_send filter

    #16240
    test programmer
    Participant

    I’ve tried this:

    
    add_filter( 'fep_filter_before_email_send', 'change_email_subject', 10, 3 );
    
    function change_email_subject($content, $post, $user_email)
    {
      $current_language = apply_filters( 'wpml_current_language', NULL );
    
      $language = get_user_meta( fep_get_userdata( $user_email, 'ID', 'email'), 'icl_admin_language', true );
    
      // set language of user
      do_action( 'wpml_switch_language', $language );
    
      $subject = "";
    
      if($post->post_type == "fep_message")
      {
          $subject = sprintf( __('ZOUTE GRAND PRIX®: New message', 'zoute_theme' ));
      }
    
      $content['subject'] = $subject;
    
      do_action( 'wpml_switch_language', $current_language );
    
      return $content;
    }
    

    When I try to dump the $content before returning it, the subject is changed correctly. The content of the message itself not (but is changed afterwards with template in /emails folder).

    But when I receive the email, the subject is not changed. It’s overwritten by the subject configured in backoffice.

    Why doesn’t it work?

    #16242
    Shamim Hasan
    Keymaster

    instead of 10 use higher priority.

Viewing 8 posts - 1 through 8 (of 8 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.