There’s the wp_mail()
function in WordPress. The headers have to be added as array without trailing \n\r
or similar.
Example
wp_mail(
'[email protected]',
'Hello World!',
'Just saying...',
array(
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1',
sprintf(
'From: %s <no-reply@%s>',
get_bloginfo('name'),
site_url()
),
sprintf( 'X-Mailer: PHP/%s', phpversion() ),
)
);
To change the content type you could as well use a filter:
<?php
/* Plugin Name: WP Mail Content Type text/html */
function wpse_97789_mail_contenttype( $content_type )
{
remove_filter( current_filter(), __FUNCTION__ );
return 'text/html';
}
// Then, whereever you need it, just add the filter before calling the function
// It removes itself after firing once
add_filter( 'wp_mail_content_type', 'wpse_97789_mail_contenttype' );
wp_mail(
'[email protected]',
'Hello World!',
'Just saying...',
array(
'MIME-Version: 1.0',
sprintf(
'From: %s <no-reply@%s>',
get_bloginfo('name'),
site_url()
),
sprintf( 'X-Mailer: PHP/%s', phpversion() ),
)
);