{"id":2457,"date":"2019-11-28T18:17:32","date_gmt":"2019-11-28T18:17:32","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2457"},"modified":"2022-02-17T07:13:49","modified_gmt":"2022-02-17T07:13:49","slug":"send-email","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/email-wordpress\/send-email","title":{"rendered":"Send email"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>  $EmailMessage = \"Hi\\nTest Message\";\n  wp_mail('someone@gmail.com', 'Email Subject', $EmailMessage);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Send email with headers set<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $EmailHeaders= array();\n  $EmailHeaders&#91;] = 'Content-Type: text\/html; charset=UTF-8';    \/\/&lt;&lt;This enables html content in the email\n  $EmailHeaders&#91;] = 'From: Me Myself &lt;me@example.net&gt;';\n  $EmailHeaders&#91;] = 'Cc: John Q Codex &lt;jqc@wordpress.org&gt;';\n  $EmailHeaders&#91;] = 'Cc: iluvwp@wordpress.org';\n\n  $EmailSubject = 'Email Subject';\n\n  $EmailMessage = \"Hi\\nTest Message\";\n  wp_mail('someone@gmail.com', $EmailSubject, $EmailMessage, $EmailHeaders);<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">HTML formatting<\/h5>\n\n\n\n<p>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.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Creating from site email address<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$FromEmailAddress = 'noreply@' . $_SERVER&#91;'HTTP_HOST'];<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Example admin alert email send<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>    $EmailMessage = '';\r\n    if ($Something)\r\n      $EmailMessage = 'Something has happened at site ' . $_SERVER&#91;'HTTP_HOST'];\r\n    \r\n    if ($EmailMessage != '')\r\n    {\r\n      \/\/SEND EMAIL\r\n      $AdminEmailAddress = get_option( 'admin_email' );\r\n      $FromEmailAddress = 'noreply@' . $_SERVER&#91;'HTTP_HOST'];\r\n      if (is_email($AdminEmailAddress))\r\n      {\r\n        $EmailHeaders= array();\r\n        $EmailHeaders&#91;] = 'Content-Type: text\/html; charset=UTF-8';    \/\/&lt;&lt;This enables html content in the email\r\n        $EmailHeaders&#91;] = \"From: $FromEmailAddress\";\r\n\r\n        $EmailSubject = 'ALERT FROM ' . get_bloginfo('name');;\r\n\r\n        wp_mail($AdminEmailAddress, $EmailSubject, $EmailMessage, $EmailHeaders);\r\n      }\r\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Send email with headers set 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 Example admin alert email send<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[207],"tags":[],"class_list":["post-2457","post","type-post","status-publish","format-standard","hentry","category-email-wordpress"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2457"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2457\/revisions"}],"predecessor-version":[{"id":3763,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2457\/revisions\/3763"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}