$EmailMessage = "Hi\nTest Message";
  wp_mail('[email protected]', '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 <[email protected]>';
  $EmailHeaders[] = 'Cc: John Q Codex <[email protected]>';
  $EmailHeaders[] = 'Cc: [email protected]';

  $EmailSubject = 'Email Subject';

  $EmailMessage = "Hi\nTest Message";
  wp_mail('[email protected]', $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 = '[email protected]' . $_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 = '[email protected]' . $_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.

Comments

Your email address will not be published.