WordPress ships with its own mail function, open_in_new wp_mail() , which wraps PHPMailer and respects whatever SMTP configuration plugins have set up:
wp_mail( $to, $subject, $message, $headers, $attachments );
Changing the sender name
add_filter( 'wp_mail_from_name', 'vortal_wp_mail_from_name' );
function vortal_wp_mail_from_name( $email_from ) {
return 'XXX';
}
Changing the sender address
add_filter( 'wp_mail_from', 'vortal_wp_mail_from' );
function vortal_wp_mail_from( $email_address ) {
return 'xxx@yyy.com';
}
By default WordPress sends from wordpress@your-domain, which is often rejected by spam filters, so
setting a real mailbox here is worth doing on every project.
Sending HTML
Messages are sent as plain text unless you declare the content type in the $headers parameter:
$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = [ 'Content-Type: text/html; charset=UTF-8' ];
wp_mail( $to, $subject, $body, $headers );
Andrew Dorokhov