{"id":488,"date":"2019-09-14T07:43:42","date_gmt":"2019-09-14T07:43:42","guid":{"rendered":"https:\/\/www.webhozz.com\/code\/?p=488"},"modified":"2019-09-14T07:49:54","modified_gmt":"2019-09-14T07:49:54","slug":"php-send-email","status":"publish","type":"post","link":"https:\/\/www.webhozz.com\/code\/php-send-email\/","title":{"rendered":"PHP : Send Email"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Fungsi PHP mail()<\/h5>\n\n\n\n<p>Mengirim pesan email sangat umum untuk sebuah aplikasi web,\nmisalnya, mengirim email sambutan ketika pengguna membuat akun di situs web kalian,\nmengirim buletin kepada member user kalian, atau mendapatkan feedback atau\nkomentar pengguna melalui formulir kontak situs web, dan sebagainya.<\/p>\n\n\n\n<p>Kalian dapat menggunakan fungsi PHP <strong><em>mail()<\/em><\/strong> bawaan untuk membuat dan mengirim pesan email ke satu atau lebih penerima secara dinamis dari aplikasi PHP kalian baik dalam bentuk teks biasa atau HTML yang diformat. Sintaks dasar fungsi ini dapat diberikan dengan:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmail(to, subject, message, headers, parameters)\n<\/pre><\/div>\n\n\n<p>Tabel berikut ini merangkum parameter dari fungsi ini.<\/p>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Parameter<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><strong>Required<\/strong>&nbsp;\u2014 The following parameters are required<\/td><\/tr><tr><td><code>to<\/code><\/td><td>Alamat email penerima.<\/td><\/tr><tr><td><code>subject<\/code><\/td><td>Subjek dari email yang akan dikirim. Parameter ini yaitu, baris subjek tidak dapat berisi karakter baris baru ( <strong><em>\\n<\/em><\/strong> ).<\/td><\/tr><tr><td><code>message<\/code><\/td><td>Menentukan pesan yang akan dikirim. Setiap baris harus dipisahkan dengan feed garis-LF ( <strong><em>\\n<\/em><\/strong> ). Garis tidak boleh lebih dari 70 karakter.<\/td><\/tr><tr><td><strong>Optional<\/strong>&nbsp;\u2014 The following parameters are optional<\/td><\/tr><tr><td><code>headers<\/code><\/td><td>Ini biasanya digunakan untuk menambahkan tajuk tambahan seperti &#8220;Dari&#8221;, &#8220;Cc&#8221;, &#8220;Bcc&#8221;. Header tambahan harus dipisahkan dengan carriage return plus line feed-CRLF ( <strong><em>\\r\\n<\/em><\/strong> ).<\/td><\/tr><tr><td><code>parameters<\/code><\/td><td>Digunakan untuk melewati (pass) parameter tambahan.<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h5 class=\"wp-block-heading\">Mengirim Email Teks Biasa<\/h5>\n\n\n\n<p>Cara paling sederhana untuk mengirim email dengan PHP adalah mengirim email teks. Pada contoh di bawah ini, pertama-tama kita mendeklarasikan variabel &#8212;- alamat email penerima, baris subjek, dan isi pesan &#8212;- kemudian kita meneruskan variabel-variabel ini ke fungsi <strong><em>mail()<\/em><\/strong> untuk mengirim email.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n$to = 'maryjane@email.com';\n$subject = 'Marriage Proposal';\n$message = 'Hi Jane, will you marry me?'; \n$from = 'peterparker@email.com';\n \n\/\/ Sending email\nif(mail($to, $subject, $message)){\n    echo 'Your mail has been sent successfully.';\n} else{\n    echo 'Unable to send email. Please try again.';\n}\n?&gt;\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\">Mengirim Email Berformat HTML<\/h5>\n\n\n\n<p>Saat kalian mengirim pesan teks menggunakan PHP, semua\nkonten akan diperlakukan sebagai teks sederhana. Kita akan meningkatkan output\nitu, dan membuat email menjadi email berformat HTML.<\/p>\n\n\n\n<p>Untuk mengirim email HTML, prosesnya akan sama. Namun, kali ini kita perlu memberikan tajuk tambahan serta pesan berformat HTML.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n$to = 'maryjane@email.com';\n$subject = 'Marriage Proposal';\n$from = 'peterparker@email.com';\n \n\/\/ To send HTML mail, the Content-type header must be set\n$headers  = 'MIME-Version: 1.0' . &quot;\\r\\n&quot;;\n$headers .= 'Content-type: text\/html; charset=iso-8859-1' . &quot;\\r\\n&quot;;\n \n\/\/ Create email headers\n$headers .= 'From: '.$from.&quot;\\r\\n&quot;.\n    'Reply-To: '.$from.&quot;\\r\\n&quot; .\n    'X-Mailer: PHP\/' . phpversion();\n \n\/\/ Compose a simple HTML email message\n$message = '&lt;html&gt;&lt;body&gt;';\n$message .= '&lt;h1 style=&quot;color:#f40;&quot;&gt;Hi Jane!&lt;\/h1&gt;';\n$message .= '&lt;p style=&quot;color:#080;font-size:18px;&quot;&gt;Will you marry me?&lt;\/p&gt;';\n$message .= '&lt;\/body&gt;&lt;\/html&gt;';\n \n\/\/ Sending email\nif(mail($to, $subject, $message, $headers)){\n    echo 'Your mail has been sent successfully.';\n} else{\n    echo 'Unable to send email. Please try again.';\n}\n?&gt;\n<\/pre><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fungsi PHP mail() Mengirim pesan email sangat umum untuk sebuah aplikasi web, misalnya, mengirim email sambutan ketika pengguna membuat akun di situs web kalian, mengirim<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-488","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Belajar PHP : Send Email - WebHozz Code<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhozz.com\/code\/php-send-email\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Belajar PHP : Send Email - WebHozz Code\" \/>\n<meta property=\"og:description\" content=\"Fungsi PHP mail() Mengirim pesan email sangat umum untuk sebuah aplikasi web, misalnya, mengirim email sambutan ketika pengguna membuat akun di situs web kalian, mengirim\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhozz.com\/code\/php-send-email\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHozz Code\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-14T07:43:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-14T07:49:54+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"headline\":\"PHP : Send Email\",\"datePublished\":\"2019-09-14T07:43:42+00:00\",\"dateModified\":\"2019-09-14T07:49:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/\"},\"wordCount\":274,\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/\",\"name\":\"Belajar PHP : Send Email - WebHozz Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\"},\"datePublished\":\"2019-09-14T07:43:42+00:00\",\"dateModified\":\"2019-09-14T07:49:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-send-email\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP : Send Email\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\",\"name\":\"WebHozz Code\",\"description\":\"Tutorial Web &amp; Pemrograman Indonesia\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/author\\\/dody\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Belajar PHP : Send Email - WebHozz Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhozz.com\/code\/php-send-email\/","og_locale":"en_US","og_type":"article","og_title":"Belajar PHP : Send Email - WebHozz Code","og_description":"Fungsi PHP mail() Mengirim pesan email sangat umum untuk sebuah aplikasi web, misalnya, mengirim email sambutan ketika pengguna membuat akun di situs web kalian, mengirim","og_url":"https:\/\/www.webhozz.com\/code\/php-send-email\/","og_site_name":"WebHozz Code","article_published_time":"2019-09-14T07:43:42+00:00","article_modified_time":"2019-09-14T07:49:54+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webhozz.com\/code\/php-send-email\/#article","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/php-send-email\/"},"author":{"name":"admin","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"headline":"PHP : Send Email","datePublished":"2019-09-14T07:43:42+00:00","dateModified":"2019-09-14T07:49:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/php-send-email\/"},"wordCount":274,"articleSection":["PHP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.webhozz.com\/code\/php-send-email\/","url":"https:\/\/www.webhozz.com\/code\/php-send-email\/","name":"Belajar PHP : Send Email - WebHozz Code","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/#website"},"datePublished":"2019-09-14T07:43:42+00:00","dateModified":"2019-09-14T07:49:54+00:00","author":{"@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"breadcrumb":{"@id":"https:\/\/www.webhozz.com\/code\/php-send-email\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhozz.com\/code\/php-send-email\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhozz.com\/code\/php-send-email\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhozz.com\/code\/"},{"@type":"ListItem","position":2,"name":"PHP : Send Email"}]},{"@type":"WebSite","@id":"https:\/\/www.webhozz.com\/code\/#website","url":"https:\/\/www.webhozz.com\/code\/","name":"WebHozz Code","description":"Tutorial Web &amp; Pemrograman Indonesia","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhozz.com\/code\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.webhozz.com\/code\/author\/dody\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/comments?post=488"}],"version-history":[{"count":2,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/488\/revisions"}],"predecessor-version":[{"id":490,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/488\/revisions\/490"}],"wp:attachment":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/media?parent=488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/categories?post=488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/tags?post=488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}