{"id":46963,"date":"2019-10-28T03:01:27","date_gmt":"2019-10-27T17:01:27","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=46963"},"modified":"2019-10-27T14:16:19","modified_gmt":"2019-10-27T04:16:19","slug":"ajax-formdata-object-no-body-php-email-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-email-tutorial\/","title":{"rendered":"Ajax FormData Object No Body PHP Email Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Ajax FormData Object No Body PHP Email Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body_email.jpg\" title=\"Ajax FormData Object No Body PHP Email Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Ajax FormData Object No Body PHP Email Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Ajax FormData Object No Body PHP Primer Tutorial' href='#afdonbphppt'>Ajax FormData Object No Body PHP Primer Tutorial<\/a> kept the pledge of the project to only have webpages with no document.body (ie. body tag) content.  But it was a closed book, so to speak.  We equate &#8230;<\/p>\n<ul>\n<li>sharing (and\/or collaboration) talk regarding web applications &#8230; with &#8230;<\/li>\n<li>accountability<\/li>\n<\/ul>\n<p> &#8230; in that yesterday&#8217;s incarnation of the web application, at least the &#8220;user experience&#8221; of using it, could not be shared (or accounted for) using the web application&#8217;s own functionality.<\/p>\n<p>But because we have used a serverside language like PHP as the programming language of choice with this project, there are ways to make it accountable <i>and<\/i> keep our pledge.  The first of these &#8220;sharing&#8221; mechanisms is email, using PHP&#8217;s <a target=_blank title='PHP mail method information' href='http:\/\/php.net\/manual\/en\/function.mail.php'>mail<\/a> function.<\/p>\n<p>How do we derive what PHP mail needs to construct an email to share this &#8220;Speech Bubble&#8221; web application, as in a snapshot of time?<\/p>\n<ul>\n<li>email (to) address &#8230; get that off the user (again via Javascript <a target=_blank title='Javascript prompt window information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_prompt.asp'>prompt<\/a> window(s)) &#8230; and &#8230;<\/li>\n<li>subject line &#8230; will hardcode as &#8220;Speech Bubbles&#8221; &#8230; and &#8230;<\/li>\n<li>HTML <b>content<\/b> (avoiding the Spam weakness of needing to perform any Javascript with it) &#8230; as per (the Javascript snippet within <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php-GETME\" title=\"no_body.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php-GETME\" title=\"no_body.php\">no_body.php<\/a> PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\" title=\"Click picture\">live run<\/a>) &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  function doemail() {<br \/>\n  ezhr=new XMLHttpRequest();<br \/>\n  eform=new FormData();<br \/>\n  eform.append('to', '\" . $emailto . \"');<br \/>\n  eform.append('subject', 'Speech Bubbles');<br \/>\n  eform.append('html', <b>'&lt;html&gt;&lt;head&gt;' + document.head.innerHTML.split('&lt;sc' + 'ript')[0].replace(' 49px',' -400px') + '&lt;\/head&gt;&lt;!--body&gt;&lt;\/body--&gt;&lt;\/html&gt;'<\/b>);<br \/>\n  ezhr.open('post', '\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php', true);<br \/>\n  ezhr.onreadystatechange = showEStuff;<br \/>\n  ezhr.send(eform);<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<\/ul>\n<p> &#8230; that tad less complex a task as it might have been had we been allowed any document.body (ie. body tag) content.  Yet another useful way PHP and Javascript (this time with <a target=_blank title='Ajax information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>Ajax<\/a> and the use of <a target=_blank title='FormData object information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FormData'>FormData<\/a> objects) can combine in their powerful ways!<\/p>\n<p>How do we differentiate functionality parts to the PHP?  As we quite frequently do, we differentiate the &#8230;<\/p>\n<ul>\n<li>single user (no sharing) Ajax\/FormData POST method that navigates within the first instantiation of the webpage &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  foreach( $_POST as $name=&gt;$val ) {<br \/>\n    if ($one == \"\") {<br \/>\n      $one=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($two == \"\") {<br \/>\n      $two=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($three == \"\") {<br \/>\n      $three=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($four == \"\") {<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else {<br \/>\n      $one=$two;<br \/>\n      $two=$three;<br \/>\n      $three=$four;<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;<br \/>\n &#8230; as distinct from &#8230;<\/li>\n<li>email location.href URL GET arguments (Javascript call) method &#8230;<br \/>\n<code><br \/>\n  if (emailto.indexOf('@') != -1) {<br \/>\n  location.href=document.URL.split('#')[0].split('?')[0] + '?to=' + encodeURIComponent(emailto) + '&rest=' + encodeURIComponent(document.title);<br \/>\n  }<br \/>\n<\/code><br \/>\n &#8230; that navigates to a new instantiation of the webpage &#8230; and we do <b>extra checks<\/b> as per &#8230;<br \/>\n&lt;?php<br \/>\n<code><br \/>\n  foreach( $_GET as $name=&gt;$val ) {<br \/>\n    if ($one == \"\") {<br \/>\n      $one=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      <b>if (strpos($one, \"@\") !== false) {<br \/>\n        $emailto=$one;<br \/>\n      } else {<\/b><br \/>\n        $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n        $title.=\"|\" . $val;<br \/>\n        $nextone++;<br \/>\n      <b>}<\/b><br \/>\n    } else if ($two == \"\") {<br \/>\n      $two=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      <b>if (strpos($two, \" ... |\") !== false) {<br \/>\n        $one=\"\";<br \/>\n        $fields=explode(\"|\", explode(\"... |\", $two)[1]);<br \/>\n        $two=\"\";<br \/>\n        $gats.=\"  You can email to an entered email address what you have so far.\";<br \/>\n        for ($ii=0; $ii&lt;sizeof($fields); $ii++) {<br \/>\n          if ($one == \"\") {<br \/>\n            $one=$fields[$ii];<br \/>\n          } else if ($two == \"\") {<br \/>\n            $two=$fields[$ii];<br \/>\n          } else if ($three == \"\") {<br \/>\n            $three=$fields[$ii];<br \/>\n          } else if ($four == \"\") {<br \/>\n            $four=$fields[$ii];<br \/>\n          } else {<br \/>\n            $one=$two;<br \/>\n            $two=$three;<br \/>\n            $three=$four;<br \/>\n            $four=$fields[$ii];<br \/>\n          }<br \/>\n          $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $fields[$ii] . \"\\\");\\n\";<br \/>\n          $title.=\"|\" . $fields[$ii];<br \/>\n          $nextone++;<br \/>\n        }<br \/>\n      } else {<\/b><br \/>\n        $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n        $title.=\"|\" . $val;<br \/>\n        $nextone++;<br \/>\n      <b>}<\/b><br \/>\n    } else if ($three == \"\") {<br \/>\n      $three=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else if ($four == \"\") {<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    } else {<br \/>\n      $one=$two;<br \/>\n      $two=$three;<br \/>\n      $three=$four;<br \/>\n      $four=str_replace(\"+\", \" \", urldecode($val));<br \/>\n      $innards.=\"\\nform.append('infld\" . $nextone . \"', \\\"\" . $val . \"\\\");\\n\";<br \/>\n      $title.=\"|\" . $val;<br \/>\n      $nextone++;<br \/>\n    }<br \/>\n  }<br \/>\n<\/code><br \/>\n?&gt;\n<\/li>\n<\/ul>\n<hr>\n<p id='afdonbphppt'>Previous relevant <a target=_blank title='Ajax FormData Object No Body PHP Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-primer-tutorial\/'>Ajax FormData Object No Body PHP Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Ajax FormData Object No Body PHP Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.jpg\" title=\"Ajax FormData Object No Body PHP Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Ajax FormData Object No Body PHP Primer Tutorial<\/p><\/div>\n<p>We think the combination of <a target=_blank title='Ajax information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>Ajax<\/a> and the use of <a target=_blank title='FormData object information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FormData'>FormData<\/a> objects interesting as a &#8220;navigation in midair&#8221; concept.  In fact, today, we got to use it, with PHP, to the point where we construct a webpage of some little functionality and interactivity that does not have any content in its <i>body<\/i> tag.  This webpage has &#8230;<\/p>\n<ul>\n<li><i>html<\/i> tags<\/li>\n<li><i>head<\/i> tag consisting of &#8230;<\/li>\n<ol>\n<li><i>title<\/i> tag<\/li>\n<li><i>style<\/i> tag<\/li>\n<li><i>script<\/i> (type=&#8217;text\/javascript&#8217;) tag<\/li>\n<\/ol>\n<\/ul>\n<p> &#8230; and that&#8217;s it.  And yet, we ask for interactive input in a Javascript <a target=_blank title='Javascript prompt window information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_prompt.asp'>prompt<\/a> window, and change content in four &#8220;speech bubble&#8221; like places within a webpage.  So take a look at the PHP <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php_GETME\" title=\"no_body.php\">no_body.php<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/no_body.php\" title=\"no_body.php\">live run<\/a>, dynamically constructing (HTML\/)CSS\/Javascript via <a target=_blank title='Ajax information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Ajax_%28programming%29'>Ajax<\/a> and the use of <a target=_blank title='FormData object information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FormData'>FormData<\/a> object returns that are &#8230;<\/p>\n<p><code><br \/>\n document.write([Ajax_FormData_return_content]);<br \/>\n<\/code><\/p>\n<p> &#8230; never leaving the initial webpage.  We try to trick you thinking otherwise perhaps, by adding to <i>document.title<\/i> the last interactively entered data snippet.  And through all this, still no need for content in any webpage <i>body<\/i> tag.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d46947' onclick='var dv=document.getElementById(\"d46947\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/style\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d46947' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d46963' onclick='var dv=document.getElementById(\"d46963\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/email\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d46963' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Ajax FormData Object No Body PHP Primer Tutorial kept the pledge of the project to only have webpages with no document.body (ie. body tag) content. But it was a closed book, so to speak. We equate &#8230; sharing (and\/or &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/ajax-formdata-object-no-body-php-email-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[2098,69,1604,257,281,352,380,2730,2212,576,652,738,849,932,997,1761,1133,1137,3125,1209,1319,1418],"class_list":["post-46963","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-accountability","tag-ajax","tag-collaboration","tag-content","tag-css","tag-document-write","tag-email","tag-formdata","tag-head","tag-html","tag-javascript","tag-mail","tag-object","tag-php","tag-programming","tag-prompt","tag-share","tag-sharing","tag-spam","tag-style","tag-tutorial","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/46963"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=46963"}],"version-history":[{"count":10,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/46963\/revisions"}],"predecessor-version":[{"id":46989,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/46963\/revisions\/46989"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=46963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=46963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=46963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}