Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author MC_Will

    (@mc_will)

    Can you please paste the full headers of one of the emails you’re getting?

    Thread Starter ucfknight04

    (@ucfknight04)

    i think i figured it out.

    Just following up here because I ran into the same issue.

    The problem was that my code for making the WP emails HTML in the first place was not being run because it hooked into PHPMailer, which isn’t being used anymore when wpMandrill is sending through the API.

    To illustrate, here is the code I used to make emails HTML and add a header and footer (popular HTML email plugins probably work in a similar way). This is the code that doesn’t work with wpMandrill.

    /*
    Add header/footer to emails. Works with standard wp_mail.
    */
    function my_send_html( $phpmailer ) {
    	// Set the original plain text message
    	$phpmailer->AltBody = wp_specialchars_decode($phpmailer->Body, ENT_QUOTES);
    	// Clean < and > around text links in WP 3.1
    	$phpmailer->Body = preg_replace('#<(https://[^*]+)>#', '$1', $phpmailer->Body);
    	// Convert line breaks & make links clickable
    	$phpmailer->Body = wpautop ( make_clickable ($phpmailer->Body) );
    
    	// Add template to message
    	if(file_exists(TEMPLATEPATH . "/email_header.html"))
    	{
    		$phpmailer->Body = file_get_contents(TEMPLATEPATH . "/email_header.html") . "\n" . $phpmailer->Body;
    	}
    	if(file_exists(TEMPLATEPATH . "/email_footer.html"))
    	{
    		$phpmailer->Body = $phpmailer->Body . "\n" . file_get_contents(TEMPLATEPATH . "/email_footer.html");
    	}
    
    	// Replace variables in email
    	global $current_user;
    	$data = array(
    				"name" => $current_user->display_name,
    				"sitename" => get_option("blogname"),
    				"display_name" => $current_user->display_name,
    				"user_email" => $current_user->user_email,
    				"subject" => $phpmailer->Subject
    			);
    	foreach($data as $key => $value)
    	{
    		$phpmailer->Body = str_replace("!!" . $key . "!!", $value, $phpmailer->Body);
    	}
    
    	do_action("my_after_phpmailer_init", $phpmailer);
    }
    function my_wp_mail_content_type( $content_type ) {	
    
    	//check for template
    	if(file_exists(TEMPLATEPATH . "/email_header.html") || file_exists(TEMPLATEPATH . "/email_footer.html"))
    	{
    		add_action('phpmailer_init', 'my_send_html', 1);
    
    		//change to html if not already
    		if( $content_type == 'text/plain')
    		{
    			$content_type = 'text/html';
    		}
    	}
    	return $content_type;
    }
    add_filter('wp_mail_content_type', 'my_wp_mail_content_type', 1);

    And here is the code I wrote to add HTML wrappers (selectively) to some emails being sent by wpMandrill. This is the code that does work with wpMandrill.

    /*
    	Add html header footer to emails sent by wpMandrill using the mandrill_payload filter
    */
    function my_email_header_footer($message)
    {
    	//only wrap emails from [email protected] and [email protected]
    	//(our invite form emails should not look official)
    	if(in_array($message['from_email'], array("[email protected]", "[email protected]")))
    	{
    		// Add template to message
    		if(file_exists(TEMPLATEPATH . "/email_header.html"))
    		{
    			$message['html'] = file_get_contents(TEMPLATEPATH . "/email_header.html") . "\n" . $message['html'];
    		}
    		if(file_exists(TEMPLATEPATH . "/email_footer.html"))
    		{
    			$message['html'] = $message['html'] . "\n" . file_get_contents(TEMPLATEPATH . "/email_footer.html");
    		}
    
    		// Replace variables in email
    		global $current_user;
    		$data = array(
    					"name" => $current_user->display_name,
    					"sitename" => get_option("blogname"),
    					"display_name" => $current_user->display_name,
    					"user_email" => $current_user->user_email,
    					"subject" => $phpmailer->Subject
    				);
    		foreach($data as $key => $value)
    		{
    			$message['html'] = str_replace("!!" . $key . "!!", $value, $message['html']);
    		}
    	}
    
    	return $message;
    }
    add_filter("mandrill_payload", "my_email_header_footer");

    Hope this helps some people. I left some of the other things I’m doing like swapping template tags in the header/footer templates and checking the sender email in case people are interested in that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not sending HTML’ is closed to new replies.