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.
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.
<?php STM_LMS_Mails::init(); class STM_LMS_Mails { public static function init() { add_action('order_created', 'STM_LMS_Mails: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']); } }
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/>
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.
@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);