1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

need a 1 minute help in code

Discussion in 'Programming' started by competent123, Oct 2, 2020.

  1. #1
    this is the code that sends email - ( its a wordpress plugin) i have tried a lot of things but in email it goes in one line, i just need to add a new line in the text. thats all
    i have tried /r/n /n , \n , <br> , . <br> . , nothing seems to work it just renders literally , ( <br> shows as <br> instead of doing a line break.


    $message = sprintf( esc_html__('Hello! Course %s is now available to learn. To complete the course, you must take all the modules and submit course projects. To complete the course, you must take all the modules and submit course projects.', 'masterstudy-lms-learning-management-system' , ) , $course_title);

    any help would be very highly appreciated.
    SEMrush
     
    competent123, Oct 2, 2020 IP
    SEMrush
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    6,851
    Likes Received:
    1,507
    Best Answers:
    26
    Trophy Points:
    425
    #2
    Not a php knowledgeable person but it has to be \r\n and not /r/n
     
    qwikad.com, Oct 2, 2020 IP
  3. competent123

    competent123 Notable Member

    Messages:
    1,740
    Likes Received:
    68
    Best Answers:
    6
    Trophy Points:
    255
    #3
    i have tried both, none of those work.
     
    competent123, Oct 3, 2020 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,530
    Likes Received:
    1,934
    Best Answers:
    247
    Trophy Points:
    515
    #4
    What are you setting the mime-type to? Can we see the full prep / headers you're putting together?

    It SHOULD be \r\n, but you have to encode it rig... oh. That escape function and the use of single quotes could be screwing up the encoding. Again, I'd have to see the whole thing.
     
    deathshadow, Oct 4, 2020 IP
  5. competent123

    competent123 Notable Member

    Messages:
    1,740
    Likes Received:
    68
    Best Answers:
    6
    Trophy Points:
    255
    #5
    <?php
    STM_LMS_Mails::init();

    class STM_LMS_Mails
    {

    public static function init()
    {
    add_action('order_created', 'STM_LMS_Mails::eek:rder_created', 10, 3);
    add_action('add_user_course', 'STM_LMS_Mails::add_user_course', 10, 2);
    }

    static function wp_mail_text_html()
    {
    add_filter('wp_mail_content_type', 'STM_LMS_Mails::wp_mail_html');
    }

    static function remove_wp_mail_text_html()
    {
    remove_filter('wp_mail_content_type', 'STM_LMS_Mails::wp_mail_html');
    }

    static function wp_mail_html()
    {
    return 'text/html';
    }

    static function order_created($user, $cart_items, $payment_code)
    {
    self::wp_mail_text_html();

    $user = STM_LMS_User::get_current_user($user);

    $user_login = $user['login'];
    $message = sprintf(esc_html__('New Order from user %s.', 'masterstudy-lms-learning-management-system'), $user_login);
    self::send_email('New Order', $message, '', array(), 'stm_lms_new_order', compact('user_login'));

    $message = esc_html__('Your Order Accepted.', 'masterstudy-lms-learning-management-system');
    self::send_email('New Order', $message, $user['email'], array(), 'stm_lms_new_order_accepted');

    self::remove_wp_mail_text_html();
    }

    static function add_user_course($user_id, $course_id)
    {
    self::wp_mail_text_html();

    $user = STM_LMS_User::get_current_user($user_id);

    if(STM_LMS_Course::check_course_author($course_id, $user_id)) return false;


    $course_title = get_the_title($course_id);
    $login = $user['login'];

    $message = sprintf(esc_html__('Course %s was added to %s.', 'masterstudy-lms-learning-management-system'), $course_title, $login);
    if (apply_filters('stm_lms_send_admin_course_notice', true)) {
    self::send_email('Course added to User', $message, '', array(), 'stm_lms_course_added_to_user', compact('course_title', 'login'));
    }

    $message = sprintf( esc_html__('Hello! Course %s is now available to learn. To complete the course, you must take all the modules and submit course projects.To complete the course, you must take all the modules and submit course projects.', 'masterstudy-lms-learning-management-system' , ) , $course_title);
    self::send_email('Course added.', $message, $user['email'], array(), 'stm_lms_course_available_for_user', compact('course_title'));

    self::remove_wp_mail_text_html();
    }

    static function send_email($subject, $message, $to = '', $additional_receivers = array(), $filter = 'stm_lms_send_email_filter', $data = array())
    {
    $to = (!empty($to)) ? $to : get_option('admin_email');
    $receivers = array_merge(array($to), $additional_receivers);

    $data = apply_filters('stm_lms_filter_email_data', array(
    'subject' => $subject,
    'message' => $message,
    'vars' => $data,
    'filter_name' => $filter
    ));

    wp_mail($receivers, $data['subject'], $data['message']);

    }


    }
     
    competent123, Oct 5, 2020 IP
  6. Efetobor Agbontaen

    Efetobor Agbontaen Active Member

    Messages:
    131
    Likes Received:
    40
    Best Answers:
    5
    Trophy Points:
    85
    #6
    After looking at the WP Documentation for esc_html__ function. I think that is the problem.
    esc_html__() will escape all HTML tags so they are rendered as string.

    Remove that function and try using <br/>
     
    Efetobor Agbontaen, Oct 12, 2020 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,530
    Likes Received:
    1,934
    Best Answers:
    247
    Trophy Points:
    515
    #7
    I mean, I know turdpress is incompetent broken insecure crap written by people who shouldn't be making websites... but did they literally go so far as to make their own brute force function to replicate the behavior of htmlspecialchars?

    What am I saying, of course they did. THEN people wonder why I call these systems junk.
     
    deathshadow, Oct 12, 2020 IP
  8. JEET

    JEET Notable Member

    Messages:
    3,724
    Likes Received:
    476
    Best Answers:
    19
    Trophy Points:
    235
    #8
    @competent123
    Try this and let us know.

    \r\n will only be converted to a new line if its inside a double quote. Your code has the string in a single quote.

    $message = sprintf( esc_html__(
    "Hello! \r\n Course %s is now available to learn. \r\n To complete the course, you must take all the modules and submit course projects. \r\n To complete the course, you must take all the modules and submit course projects. ",
    'masterstudy-lms-learning-management-system' ) , $course_title);
     
    Last edited: Oct 12, 2020
    JEET, Oct 12, 2020 IP