{"id":12490,"date":"2020-04-17T11:50:53","date_gmt":"2020-04-17T02:50:53","guid":{"rendered":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12490"},"modified":"2024-05-28T17:53:23","modified_gmt":"2024-05-28T08:53:23","slug":"php%e3%81%a7sendgrid%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92%e4%b8%80%e6%96%89%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12490","title":{"rendered":"PHP\u3067SendGrid\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u4e00\u6589\u9001\u4fe1\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/gYaA4EL-8TuAge_LpO9S8PDmADJpA-uCxVwPObtGyL7tJz.width-808.png\" alt=\"PHP\u3067SendGrid\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092\u4e00\u6589\u9001\u4fe1\u3059\u308b\u65b9\u6cd5\" width=\"100%\" class=\"aligncenter size-full wp-image-12491\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/gYaA4EL-8TuAge_LpO9S8PDmADJpA-uCxVwPObtGyL7tJz.width-808.png 808w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/gYaA4EL-8TuAge_LpO9S8PDmADJpA-uCxVwPObtGyL7tJz.width-808-300x150.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/gYaA4EL-8TuAge_LpO9S8PDmADJpA-uCxVwPObtGyL7tJz.width-808-768x384.png 768w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/p>\n<blockquote>\n<p>\u3053\u306e\u8a18\u4e8b\u306f <a href=\"https:\/\/www.twilio.com\/blog\/send-bulk-emails-php-twilio-sendgrid\" target=\"_blank\">How to Send Bulk Emails in PHP using Twilio SendGrid<\/a> \u306e\u6284\u8a33\u3067\u3059\u3002<\/p>\n<\/blockquote>\n<p>\u30a4\u30d9\u30f3\u30c8\u306e\u4f01\u753b\u306b\u306f\u3001\u51fa\u5e2d\u8005\u3068\u306e\u983b\u7e41\u304b\u3064\u9069\u5207\u306a\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002\u30bf\u30a4\u30e0\u30ea\u30fc\u306b\u8a73\u7d30\u306a\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u3089\u306a\u3044\u3068\u3001\u51fa\u5e2d\u8005\u306f\u6df7\u4e71\u3057\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u305d\u3057\u3066\u3059\u3079\u3066\u304c\u8a08\u753b\u901a\u308a\u306b\u9032\u3093\u3067\u3082\u3001\u30a4\u30d9\u30f3\u30c8\u958b\u50ac\u65e5\u304c\u8fd1\u3065\u3044\u305f\u3089\u30b2\u30b9\u30c8\u3078\u306e\u30ea\u30de\u30a4\u30f3\u30c9\u30e1\u30fc\u30eb\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.twilio.com\/docs\/sendgrid\/glossary\/bulk-email-service\" rel=\"noopener\" target=\"_blank\">\u4e00\u6589\u914d\u4fe1\u30e1\u30fc\u30eb<\/a>\u306f\u3001\u5168\u54e1\u306b\u60c5\u5831\u3092\u5171\u6709\u3059\u308b\u6700\u9069\u306a\u624b\u6bb5\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<a href=\"https:\/\/sendgrid.kke.co.jp\/\" rel=\"noopener\" target=\"_blank\">Twilio SendGrid<\/a>\u3092\u4f7f\u7528\u3057\u3066PHP\u3067\u4e00\u6589\u914d\u4fe1\u3092\u884c\u3046\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.php.net\/manual\/en\/control-structures.foreach.php\" rel=\"noopener\" target=\"_blank\">foreach<\/a>\u6587\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306e\u914d\u5217\u3092\u89e3\u6790\u3057\u3001<a href=\"https:\/\/sendgrid.com\/docs\/for-developers\/sending-email\/personalizations\/\" rel=\"noopener\" target=\"_blank\">personalization\u30af\u30e9\u30b9<\/a>\u3067\u5b9b\u5148\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002Twilio SendGrid\u3067\u306f\u3001\u4e00\u6589\u914d\u4fe1\u30e1\u30fc\u30eb\u3092\u30d1\u30fc\u30bd\u30ca\u30e9\u30a4\u30ba\u3057\u305f\u308a\u3001\u500b\u3005\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u5fdc\u3058\u3066\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u5fc5\u8981\u306a\u30c4\u30fc\u30eb<\/h3>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3092\u5b9f\u65bd\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3082\u306e\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<table border>\n<tr>\n<td>\n\u30fb<a href=\"https:\/\/sendgrid.kke.co.jp\/app?p=signup.index\" rel=\"noopener\" target=\"_blank\">Twilio SendGrid\u306e\u30a2\u30ab\u30a6\u30f3\u30c8<\/a><br \/>\n\u30fb<a href=\"https:\/\/getcomposer.org\/\" rel=\"noopener\" target=\"_blank\">Composer<\/a>\u304c\u30b0\u30ed\u30fc\u30d0\u30eb\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u305fPHP\u306e\u958b\u767a\u74b0\u5883\n<\/td>\n<\/tr>\n<\/table>\n<h3>Twilio SendGrid\u3092\u4f7f\u3046<\/h3>\n<p>\u307e\u305a\u306f\u3001<a href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12474\" rel=\"noopener\" target=\"_blank\">PHP\u304b\u3089SendGrid\u3092\u4f7f\u3063\u3066\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5<\/a>\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002\u4e0a\u306e\u8a18\u4e8b\u3067\u4f5c\u6210\u3057\u305f\u74b0\u5883\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b<a href=\"https:\/\/github.com\/themarcusbattle\/php-sendgrid\" rel=\"noopener\" target=\"_blank\">\u30ea\u30dd\u30b8\u30c8\u30ea<\/a>\u3092\u30af\u30ed\u30fc\u30f3\u3059\u308c\u3070\u5165\u624b\u3067\u304d\u307e\u3059\u3002\u672c\u8a18\u4e8b\u306f\u3053\u306e\u7d9a\u304d\u304b\u3089\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$ git clone git@github.com:themarcusbattle\/php-sendgrid.git\r\n$ cd php-sendgrid\r\n<\/pre>\n<h3>\u4e00\u6589\u9001\u4fe1\u306e\u30b3\u30fc\u30c9\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067 <span style=\"background-color:#d3d3d3\">email.php<\/span> \u3092\u958b\u304d\u3001\u5185\u5bb9\u3092\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306b\u66f8\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\r\nrequire 'vendor\/autoload.php';\r\n\r\nuse SendGrid\\Mail\\Personalization;\r\nuse SendGrid\\Mail\\To;\r\n\r\n\/\/ Load our `.env` variables\r\n$dotenv = Dotenv\\Dotenv::create(__DIR__);\r\n$dotenv-&gt;load();\r\n\r\n\/\/ Declare a new SendGrid Mail object\r\n$email = new \\SendGrid\\Mail\\Mail();\r\n\r\n\/\/ Define the primary email\r\n$email-&gt;setFrom(&quot;your@email.com&quot;, &quot;Your Name&quot;);\r\n$email-&gt;setSubject(&quot;Group Email to Twilio Subscribers&quot;);\r\n$email-&gt;addTo(&quot;first@recipient.com&quot;, &quot;First Recipient&quot;);\r\n\r\n\/\/ Define the additional email addresses\r\n$email_addresses = &#x5B;\r\n    'second@recipient.com',\r\n];\r\n\r\nforeach ( $email_addresses as $email_address ) {\r\n\r\n    $personalization = new Personalization();\r\n    $personalization-&gt;addTo( new To( $email_address ) );\r\n\r\n    $email-&gt;addPersonalization( $personalization );\r\n}\r\n\r\n\r\n$email-&gt;addContent(&quot;text\/plain&quot;, &quot;Sending bulk emails is easy with SendGrid&quot;);\r\n$email-&gt;addContent(&quot;text\/html&quot;, &quot;Sending bulk emails is easy with SendGrid&quot;);\r\n\r\n$sendgrid = new \\SendGrid(getenv('SENDGRID_API_KEY'));\r\n\r\ntry {\r\n    $response = $sendgrid-&gt;send($email);\r\n    print $response-&gt;statusCode() . &quot;\\n&quot;;\r\n    print_r($response-&gt;headers());\r\n    print $response-&gt;body() . &quot;\\n&quot;;\r\n    echo &quot;email sent!\\n&quot;;\r\n} catch (Exception $e) {\r\n    echo 'Caught exception: '. $e-&gt;getMessage() .&quot;\\n&quot;;\r\n}\r\n<\/pre>\n<p>Personalization\u30af\u30e9\u30b9\u306f\u3001<span style=\"background-color:#d3d3d3\">Mail<\/span>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bpersonalizations\u914d\u5217\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u52d5\u4f5c\u3057\u307e\u3059\u30021\u3064\u3081\u306e\u5b9b\u5148\u304c\u3001\u65b0\u898f\u4f5c\u6210\u3055\u308c\u305f<span style=\"background-color:#d3d3d3\">$email<\/span>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u304a\u6c17\u3065\u304d\u3067\u3057\u3087\u3046\u304b\u3002\u8ffd\u52a0\u3055\u308c\u305f\u5b9b\u5148\u306f\u3001\u305d\u308c\u305e\u308c<span style=\"background-color:#d3d3d3\">$email_addresses<\/span>\u306e\u914d\u5217\u3067\u5b9a\u7fa9\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>SendGrid Mail\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5b9b\u5148\u30921\u3064\u3057\u304b\u53d7\u3051\u4ed8\u3051\u306a\u3044\u306e\u3067\u3001Personalization\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u5b9b\u5148\u3092\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<span style=\"background-color:#d3d3d3\">foreach<\/span>\u30eb\u30fc\u30d7\u3067<span style=\"background-color:#d3d3d3\">$email_addresses<\/span>\u3092\u53cd\u5fa9\u51e6\u7406\u3055\u305b\u307e\u3059\u3002\u305d\u306e\u51e6\u7406\u306e\u4e2d\u3067\u65b0\u3057\u3044Personalization\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u3001<span style=\"background-color:#d3d3d3\">addTo<\/span>\u30e1\u30bd\u30c3\u30c9\u3067\u5b9b\u5148\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u5404Personalization\u304c\u89aa\u306e\u30e1\u30fc\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<span style=\"background-color:#d3d3d3\">$email<\/span>\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3068\u3001\u30e1\u30fc\u30eb\u30921\u901a\u9001\u4fe1\u3059\u308b\u5834\u5408\u3068\u540c\u3058\u30ed\u30b8\u30c3\u30af\u3067\u3059\u3079\u3066\u306e\u5b9b\u5148\u306b\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30c6\u30b9\u30c8\u3059\u308b<\/h3>\n<p>\u30eb\u30fc\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304b\u3089\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3057\u3087\u3046: <span style=\"background-color:#d3d3d3\">php email.php<\/span><\/p>\n<p>\u6b63\u5e38\u306b\u5b9f\u884c\u3067\u304d\u308c\u3070\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306b<span style=\"background-color:#d3d3d3\">emails sent!<\/span>\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/QfsaFHGrwwzFdO2_JqNPgGgKd6lLGsmmimFQavypV2sg-m.width-800.png\" alt=\"\u30c6\u30b9\u30c8\u3059\u308b\" width=\"100%\" class=\"aligncenter size-full wp-image-12492\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/QfsaFHGrwwzFdO2_JqNPgGgKd6lLGsmmimFQavypV2sg-m.width-800.png 800w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/QfsaFHGrwwzFdO2_JqNPgGgKd6lLGsmmimFQavypV2sg-m.width-800-300x113.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/QfsaFHGrwwzFdO2_JqNPgGgKd6lLGsmmimFQavypV2sg-m.width-800-768x288.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/O3k_ROEjwDlaR1eOiM06KaO8ClZwflKPyXyCyeW0bMmD_k.width-800.png\" alt=\"\u30c6\u30b9\u30c8\u3059\u308b\" width=\"100%\" class=\"aligncenter size-full wp-image-12493\" srcset=\"https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/O3k_ROEjwDlaR1eOiM06KaO8ClZwflKPyXyCyeW0bMmD_k.width-800.png 800w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/O3k_ROEjwDlaR1eOiM06KaO8ClZwflKPyXyCyeW0bMmD_k.width-800-300x144.png 300w, https:\/\/sendgrid.kke.co.jp\/blog\/wp\/wp-content\/uploads\/2020\/04\/O3k_ROEjwDlaR1eOiM06KaO8ClZwflKPyXyCyeW0bMmD_k.width-800-768x370.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>Twilio SendGrid\u3092\u4f7f\u3048\u3070\u7c21\u5358\u306b\u4e00\u6589\u9001\u4fe1\u3092\u884c\u3048\u3001\u53d7\u4fe1\u8005\u5168\u54e1\u306b\u6700\u65b0\u306e\u60c5\u5831\u3092\u63d0\u4f9b\u3067\u304d\u308b\u3053\u3068\u3067\u9ad8\u3044\u4fe1\u983c\u6027\u3092\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u9001\u4fe1\u30e1\u30fc\u30eb\u3092\u30d6\u30e9\u30c3\u30b7\u30e5\u30a2\u30c3\u30d7\u3059\u308b\u969b\u306f\u3001<a href=\"https:\/\/sendgrid.com\/docs\/for-developers\/sending-email\/personalizations\/\" rel=\"noopener\" target=\"_blank\">personalization\u30af\u30e9\u30b9<\/a>\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u306f How to Send Bulk Emails in PHP using Twilio SendGrid \u306e\u6284\u8a33\u3067\u3059\u3002 \u30a4\u30d9\u30f3\u30c8\u306e\u4f01\u753b\u306b\u306f\u3001\u51fa\u5e2d\u8005\u3068\u306e\u983b\u7e41\u304b\u3064\u9069\u5207\u306a\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002\u30bf\u30a4\u30e0\u30ea\u30fc <a class=\"read-more\" href=\"https:\/\/sendgrid.kke.co.jp\/blog\/?p=12490\">&#8230;\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":12491,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-12490","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12490"}],"version-history":[{"count":9,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12490\/revisions"}],"predecessor-version":[{"id":17796,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/12490\/revisions\/17796"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=\/wp\/v2\/media\/12491"}],"wp:attachment":[{"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sendgrid.kke.co.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}