• I’ve found that the plugin doesn’t deal with address formatting properly. Since it overrides wp_mail() you can only pass address in as an array or comma-separated string. But if the format includes a name, e.g. ‘”User Name” <[email protected]>’, this will be passed straight through to the Mandrill API and fail.

    To fix this, I’m using the following filter:

    add_filter( 'mandrill_payload', 'my_mandrill_payload', PHP_INT_MAX );
    function my_mandrill_payload( $payload ) {
    
    	// Break out quoted names to proper format for Mandrill
    	$new_to = array();
    	foreach ( $payload[ 'to' ] as $to_address ) :
    
    		// Is there a name?
    		if ( preg_match( '/([^<]*)<([^>]+)>/', $to_address['email'], $matches ) === 1 ) :
    
    			// Include name
    			$new_to[] = array(
    				'email' => trim( $matches[ 2 ] ),
    				'name'  => trim( trim( $matches[ 1 ] ), '"\'' ),
    				'type'  => 'to',
    			);
    
    		else :
    
    			// No name
    			$new_to[] = array(
    				'email' => $to_address['email'],
    				'type'  => 'to',
    			);
    
    		endif;
    
    	endforeach;
    
    	// Pass 'to' through
    	$payload['to'] = $new_to;
    
    	return $payload;
    
    }

    What with this and other things (we’d really like to tidy up the large amount of PHP notice/warning errors, and handling of HTML vs. text could be slicker), we’d love to contribute to the plugin. However, I’m rusty with SVN, and work much better with Git. Any chance dev code could be cloned and worked with on GitHub?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘proper address format’ is closed to new replies.