• Resolved RonaldS

    (@norus)


    Messages template works well after design it. But how do I call the template when using a self created plugin.
    Here the code I am using now. The result is raw text. I hope you can give me an advise how to include the Newsletter template into every wp_mail call as below:

    $to 	= $email_address;	
    $headers = "MIME-Version: 1.0" . "\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\n";
    $subject = 'Invitation from '.$from;
    $message = $invitation_source_text;
    	
    $mail 	= wp_mail($to, $subject, $message, $headers);	
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter RonaldS

    (@norus)

    Hi, I found a solution, but it works till sending the email. When receiving I get an empty email.

    Here what I done so far:

    function email_template($message){	
    	$lang = '';
    	$lang = pll_current_language(); 
    	$tmpl = 'newsletter_subscription_template_'.$lang;
    	$options_template = get_option($tmpl);	
    	if($options_template) {
    		$template = implode($options_template); 
    	} else {
    		$template = '{message}';
    	}
    	$message = str_replace('{message}', $message, $template);	
    	return $message;
    }
    add_action( 'email_template', 'email_template' ); 

    In the code I call the function:

    	$headers = "MIME-Version: 1.0" . "\n";
    	$headers .= "Content-type:text/html;charset=UTF-8" . "\n";
    	$template = email_template($message);		
    	$mail 	= wp_mail($to, $subject, $template, $headers);	

    When echo wp_mail($to, $subject, $template, $headers); the correct template is loaded including the text instead of {message}.
    But when running the code I get empty email.

    It seems that you have to declare a function to tell WP the content type.
    But it still does not work.

    function wpse27856_set_content_type(){
        return "text/html";
    }
    add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );

    Any idea how to solve this?

    Regards,
    Ronald

    • This reply was modified 6 years, 2 months ago by RonaldS.
    • This reply was modified 6 years, 2 months ago by RonaldS.
    • This reply was modified 6 years, 2 months ago by RonaldS.
    Thread Starter RonaldS

    (@norus)

    Ok. got it working. function wpse27856_set_content_type() is overdone here when already using $headers .= “Content-type:text/html;
    Thanks for your wonderful plugin.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use Messages template within new created Plugin’ is closed to new replies.