{"id":794,"date":"2023-12-17T23:59:29","date_gmt":"2023-12-17T14:59:29","guid":{"rendered":"https:\/\/web.cloudfree.jp\/journal\/?p=794"},"modified":"2023-12-21T08:59:43","modified_gmt":"2023-12-20T23:59:43","slug":"phpmailer%e3%81%a7smtp%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/web.cloudfree.jp\/journal\/phpmailer%e3%81%a7smtp%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1\/","title":{"rendered":"PHPMailer\u3067SMTP\u30e1\u30fc\u30eb\u9001\u4fe1"},"content":{"rendered":"<h3 class=\"wp-block-post-title\">PHPMailer\u3067SMTP\u30e1\u30fc\u30eb\u9001\u4fe1<\/h3>\n\n\n<p class=\"has-tertiary-color has-text-color has-background has-small-font-size\" style=\"background-color:#8d8dd8;margin-top:0;margin-right:0;margin-bottom:0;margin-left:0;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0\">2023-12-17 \u8a18\u8f09<br>\u6982\u8981 : sendmail\u3067\u306f\u8fd4\u4fe1\u4e0d\u53ef\u306e\u30e1\u30fc\u30eb\u306b\u306a\u308b\u306e\u3067\u3001\u81ea\u5206\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u3002Keyword : PHPMailer, sendmail, PHP, SMTP,  <\/p>\n\n\n\n<p>Gmail\u3092\u4f8b\u306b\u3001Gmail\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u7528\u3044\u3066\u30e1\u30fc\u30eb\u9001\u4fe1\u3059\u308b\u8a2d\u5b9a\u3092\u3057\u3066\u307f\u307e\u3059\u3002<br>Gmail\u306f\u8a8d\u8a3c\u65b9\u6cd5\u3068\u3057\u3066\u3001OAuth2.0\u3068\uff12\u6bb5\u968e\u8a8d\u8a3c\u306e\u3075\u305f\u3064\u304c\u3042\u308a\u307e\u3059\u3002\uff12\u6bb5\u968e\u8a8d\u8a3c\u306e\u307b\u3046\u304c\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u306e\u3067\u307e\u305a\u306f\u305d\u3061\u3089\u3092\u3002<br><br>\uff27\u30e1\u30fc\u30eb\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306f\u3059\u3067\u306b\u6301\u3063\u3066\u3044\u308b\u3082\u306e\u3068\u3057\u307e\u3059\u3002<br>myaccount@gmail.com<br>\u3068\u8aac\u660e\u4e0a\u306f\u3057\u307e\u3059\u3002<br>https:\/\/mail.google.com\/mail<br>\u3067Gmail\u306e\u753b\u9762\u3092\u51fa\u3057\u3001<br>\u6b6f\u8eca\u2192\u3059\u3079\u3066\u306e\u8a2d\u5b9a\u3092\u8868\u793a\u2192\u30a2\u30ab\u30a6\u30f3\u30c8\u3068\u30a4\u30f3\u30dd\u30fc\u30c8\u2192\u30a2\u30ab\u30a6\u30f3\u30c8\u8a2d\u5b9a\u3092\u5909\u66f4:<br>[\u305d\u306e\u4ed6\u306e Google \u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u8a2d\u5b9a]<br>https:\/\/myaccount.google.com\/u\/0\/?hl=ja<br>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u2192\uff12\u6bb5\u968e\u8a8d\u8a3c\u30d7\u30ed\u30bb\u30b9<br>\u3067\u672c\u4eba\u78ba\u8a8d\u306e\u306e\u3061\u3001<br>[2 \u6bb5\u968e\u8a8d\u8a3c\u30d7\u30ed\u30bb\u30b9\u3092\u6709\u52b9\u306b\u3057\u307e\u3059\u304b\uff1f]\u2192\u6709\u52b9\u306b\u3059\u308b<br>\u3075\u305f\u305f\u3073<br>\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u2192\uff12\u6bb5\u968e\u8a8d\u8a3c\u30d7\u30ed\u30bb\u30b9<br>\u304b\u3089\u5165\u308a\u3001\u6700\u4e0b\u6bb5\u306e[\u30a2\u30d7\u30ea \u30d1\u30b9\u30ef\u30fc\u30c9]<br>\u30a2\u30d7\u30ea \u30d1\u30b9\u30ef\u30fc\u30c9 \u306a\u3057 \u2192<br>App name\u306e \u5165\u529b<br>\uff08\u3053\u3053\u306f\u8907\u6570\u306e\u30a2\u30d7\u30ea\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8a2d\u5b9a\u3057\u305f\u5834\u5408\u306e\u8b58\u5225\u540d\u3067\u3001\u3053\u306e\u5024\u3092\u9001\u4fe1\u8a2d\u5b9a\u3067\u7528\u3044\u308b\u3053\u3068\u306f\u306a\u3044\u3002\u3064\u307e\u308a\u4f55\u7528\u304b\u81ea\u5206\u304c\u308f\u304b\u308c\u3070\u3088\u3044\u3002\uff09<br>for PHPMailer on cloudfree<br>\u3068\u304b\u3092\u5165\u308c\u307e\u3059\u3068\u3001\u30c0\u30a4\u30a2\u30ed\u30b0\u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br>\uff14\u6841\u306e\uff14\u30d6\u30ed\u30c3\u30af\u3067\uff11\uff16\u6587\u5b57\u3002\u3053\u308c\u304c\u91cd\u8981\u3067\u3059\u3002<br>aaaa bbbb cccc dddd<br>\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3068\u30b9\u30da\u30fc\u30b9\u3092\u7701\u3044\u305f16\u6587\u5b57\u304c\u30ed\u30b0\u30a4\u30f3\u60c5\u5831\u306b\u306a\u308a\u307e\u3059\u3002<br>username : myaccount@gmail.com<br>password : aaaabbbbccccdddd<br><br>\u3064\u304e\u306bComposer\u3067PHPMailer\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<br>\u4f8b\u3068\u3057\u3066 htdocs\\maillib \u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>C:\\pgm\\Apache24\\htdocs\\maillib&gt;composer require phpmailer\/phpmailer\nUsing version ^6.9 for phpmailer\/phpmailer\n.\/composer.json has been created\nRunning composer update phpmailer\/phpmailer\nLoading composer repositories with package information\nUpdating dependencies\nLock file operations: 1 install, 0 updates, 0 removals\n  - Locking phpmailer\/phpmailer (v6.9.1)\nWriting lock file\nInstalling dependencies from lock file (including require-dev)\nPackage operations: 1 install, 0 updates, 0 removals\n  - Installing phpmailer\/phpmailer (v6.9.1): Extracting archive\n7 package suggestions were added by new dependencies, use `composer suggest` to see details.\nGenerating autoload files\n1 package you are using is looking for funding.\nUse the `composer fund` command to find out more!<\/code><\/pre><\/div>\n\n\n\n<p>\u3067\u306fphp\u304b\u3089\u9001\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<br>myaccount@gmail.com\u3000\u304c\u9001\u4fe1\u5143\u3002<br>dummymail@gmail.com \u3092\u9001\u4ed8\u5148\u3068\u3057\u307e\u3059\u3002<br>htdocs\\maillib\\sendmail_gmail.php\u3092\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"sendmail_gmail.php\" data-lang=\"PHP\"><code>&lt;?php\nrequire_once &#39;vendor\/autoload.php&#39;;\nrequire_once &#39;vendor\/phpmailer\/phpmailer\/language\/phpmailer.lang-ja.php&#39;;\n\nuse PHPMailer\\PHPMailer\\PHPMailer;\nuse PHPMailer\\PHPMailer\\Exception;\n\n$mail = new PHPMailer(true);\n\n\/\/$mail-&gt;SMTPDebug = 2; \/\/\u30c7\u30d0\u30c3\u30b0\u7528 2\n$mail-&gt;setLanguage(&#39;ja&#39;, &#39;vendor\/phpmailer\/phpmailer\/language\/&#39;);\n$mail-&gt;CharSet = &quot;utf-8&quot;;\n$mail-&gt;Encoding = &quot;base64&quot;;\n\n\/\/\u8a8d\u8a3c\u8a2d\u5b9a\n$mail-&gt;isSMTP();\n$mail-&gt;Host = &#39;smtp.gmail.com&#39;;\n$mail-&gt;SMTPAuth = true;\n$mail-&gt;Port = 587;\n$mail-&gt;SMTPSecure = &#39;tls&#39;;\n$mail-&gt;Username = &#39;myaccount@gmail.com&#39;; \/\/ Google\u30ed\u30b0\u30a4\u30f3\u30e6\u30fc\u30b6\u540d\n$mail-&gt;Password = &#39;aaaabbbbccccdddd&#39;;      \/\/ Google\u30a2\u30d7\u30ea\u30d1\u30b9\u30ef\u30fc\u30c9\n\n\/\/\u5dee\u51fa\u4eba\n$mail-&gt;setFrom(&#39;myaccount@gmail.com&#39;);\n\/\/\u5b9b\u5148\n$mail-&gt;addAddress(&#39;dummymail@gmail.com&#39;);\n\n\/\/\u4ef6\u540d\n$mail-&gt;Subject = &#39;PHPMailer\u304b\u3089\u9001\u308a\u307e\u3059&#39;;\n\/\/\u672c\u6587\n$mail-&gt;Body = &quot;\u6625\u306f\u3042\u3051\u307c\u306e\u3002\\n\u3084\u3046\u3084\u3046\u767d\u304f\u306a\u308a\u3086\u304f\u5c71\u304e\u306f\\n\u3059\u3053\u3057\u3042\u304b\u308a\u3066&quot;;\n\n\/\/\u30e1\u30fc\u30eb\u9001\u4fe1\ntry {\n  $mail-&gt;send();\n  echo &#39;\u5c4a\u304d\u307e\u3057\u305f\u304b\uff1f&#39;;\n} catch (Exception $e) {\n  echo &#39;\u5931\u6557: &#39;, $mail-&gt;ErrorInfo.PHP_EOL;\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u30b5\u30fc\u30d0\u306f\u3082\u3061\u308d\u3093\u3001\u30ed\u30fc\u30ab\u30eb\u74b0\u5883\u304b\u3089\u3067\u3082\u9001\u4fe1\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u30e1\u30fc\u30eb\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u6b63\u3057\u3044\u3082\u306e\u306b\u66f8\u304d\u63db\u3048\u308c\u3070<br>https:\/\/localhost\/maillib\/sendmail_gmail.php<br>\u3067\u5b9f\u969b\u306b\u9001\u4fe1\u3055\u308c\u308b\u3067\u3057\u3087\u3046\u3002<br>\u5c4a\u304b\u306a\u3044\u5834\u5408\u306f<br>$mail->SMTPDebug = 2; \/\/\u30c7\u30d0\u30c3\u30b0\u7528 2<br>\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u5916\u3057\u3066\u539f\u56e0\u3092\u63a2\u308a\u307e\u3059\u3002<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHPMailer\u3067GMail\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u304b\u3089\u30e1\u30fc\u30eb\u9001\u4fe1\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002\uff12\u6bb5\u968e\u8a8d\u8a3c\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u30b3\u30fc\u30c9\u306f\u7c21\u6613\u3067\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":796,"comment_status":"open","ping_status":"closed","sticky":false,"template":"wp-custom-template-x24-index","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[110,108,109,105],"_links":{"self":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts\/794"}],"collection":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/comments?post=794"}],"version-history":[{"count":0,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/posts\/794\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/media\/796"}],"wp:attachment":[{"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/media?parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/categories?post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.cloudfree.jp\/journal\/wp-json\/wp\/v2\/tags?post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}