$EmailMessage = "Hi\nTest Message";
wp_mail('so*****@gm***.com', 'Email Subject', $EmailMessage);
Send email with headers set
$EmailHeaders= array();
$EmailHeaders[] = 'Content-Type: text/html; charset=UTF-8'; //<<This enables html content in the email
$EmailHeaders[] = 'From: Me Myself <**@ex*****.net>';
$EmailHeaders[] = 'Cc: John Q Codex <jq*@wo*******.org>';
$EmailHeaders[] = 'Cc: il****@wo*******.org';
$EmailSubject = 'Email Subject';
$EmailMessage = "Hi\nTest Message";
wp_mail('so*****@gm***.com', $EmailSubject, $EmailMessage, $EmailHeaders);
HTML formatting
No need for anything special, just include html tags within the email body as if writing the html for the body of a normal html page.
Creating from site email address
$FromEmailAddress = 'noreply@' . $_SERVER['HTTP_HOST'];
Example admin alert email send
$EmailMessage = '';
if ($Something)
$EmailMessage = 'Something has happened at site ' . $_SERVER['HTTP_HOST'];
if ($EmailMessage != '')
{
//SEND EMAIL
$AdminEmailAddress = get_option( 'admin_email' );
$FromEmailAddress = 'noreply@' . $_SERVER['HTTP_HOST'];
if (is_email($AdminEmailAddress))
{
$EmailHeaders= array();
$EmailHeaders[] = 'Content-Type: text/html; charset=UTF-8'; //<<This enables html content in the email
$EmailHeaders[] = "From: $FromEmailAddress";
$EmailSubject = 'ALERT FROM ' . get_bloginfo('name');;
wp_mail($AdminEmailAddress, $EmailSubject, $EmailMessage, $EmailHeaders);
}
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.