mircobabini
1/7/2016 - 4:46 PM

better__wp_mail.php

<?php
/**
 * @version 20150108
 */
if( ! function_exists( 'better__wp_mail' ) ) :

	function better__contact_form_email( $to, $from, $subject, $message ){
		list( $from_name, $from_email ) = $from;
		if( function_exists( 'mb_encode_mimeheader' ) ){
			$from_name = mb_encode_mimeheader( $from_name );
		}
		// $message .= '<br><br>Rispondi a: <a href="mailto:'.$from_email.'">'.$from_name.' ('.$from_email.')</a>';
		return better__wp_mail( $to, $from, $subject, $message );
	}
	function better__wp_mail( $to, $from, $subject, $message, $headers = array(), $attachments = array() ){
		list( $from_name, $from_email ) = $from;
		if( function_exists( 'mb_encode_mimeheader' ) ){
			$from_name = mb_encode_mimeheader( $from_name );
		}
		add_filter( 'wp_mail_content_type', 'better__wp_mail__set_html_content_type' );
		add_filter( 'wp_mail_from', function( $email )use( $from_email ){ return $from_email; }, 99 );
		add_filter( 'wp_mail_from_name', function( $name )use( $from_name ){ return $from_name; }, 99 );
		$status = wp_mail( $to, $subject, $message, $headers, $attachments );
		remove_filter( 'wp_mail_content_type', 'better__wp_mail__set_html_content_type' );
		return $status;
	}
	function better__wp_mail__set_html_content_type(){
		return 'text/html';
	}

endif;