{"id":3407,"date":"2021-07-25T10:43:08","date_gmt":"2021-07-25T01:43:08","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=3407"},"modified":"2024-01-16T00:41:32","modified_gmt":"2024-01-15T15:41:32","slug":"post-3407","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/3407","title":{"rendered":"PHPMailer\u3092\u4f7f\u3063\u3066\u30e1\u30fc\u30eb\u3092SMTP\u9001\u4fe1\u3059\u308b\u65b9\u6cd5(Composer\u7121\u3057)"},"content":{"rendered":"<p>PHP\u3067\u30e1\u30fc\u30eb\u3092SMTP\u9001\u4fe1\u3057\u305f\u304b\u3063\u305f\u3002\u307e\u305f\u3001\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3060\u3063\u305f\u306e\u3067Composer\u3092\u3069\u3046\u4f7f\u3046\u306e\u304b\u5206\u304b\u3089\u306a\u3044\u70ba\u3001\u6700\u4f4e\u9650\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u307f\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057PHPMailer\u3092\u4f7f\u3044\u305f\u304b\u3063\u305f\u3002\u5c1a\u3001<a href=\"https:\/\/taitan916.info\/blog\/archives\/1830\" target=\"_blank\" rel=\"noopener\">\u904e\u53bb\u306bPHPMailer\u3092\u4f7f\u3046\u3053\u3068\u306f\u3042\u3063\u305f<\/a>\u304c\u3001\u4f55\u6545\u304b\u9001\u4fe1\u3067\u304d\u306a\u304f\u306a\u3063\u3066\u3044\u305f\u306e\u3067\u65b0\u305f\u306b\u4f7f\u3044\u65b9\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>Gmail\u306eSMTP\u30b5\u30fc\u30d0\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408(2024\/01\/12\u8ffd\u8a18)<\/h2>\n<p>Gmail\u306eSMTP\u30b5\u30fc\u30d0\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u8a2d\u5b9a\u306e\u554f\u984c\u3067\u3053\u306e\u8a18\u4e8b\u306e\u65b9\u6cd5\u3067\u306f\u9001\u4fe1\u3067\u304d\u306a\u3044\u3002\u305d\u306e\u305f\u3081\u8ffd\u8a18\u3057\u305f\u300c<a href=\"https:\/\/taitan916.info\/blog\/archives\/3954\" target=\"_blank\" rel=\"noopener\">PHPMailer\u3067Gmail\u306eSMTP\u30b5\u30fc\u30d0\u3092\u7d4c\u7531\u3057\u3066\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3092\u53c2\u7167\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>PHPMailer\u306e\u6e96\u5099<\/h2>\n<p>\u4ee5\u4e0b\u3088\u308a\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u5c55\u958b\u3059\u308b\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/PHPMailer\/PHPMailer\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/PHPMailer\/PHPMailer<\/a><\/p>\n<p>src\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306e\u300cPHPMailer.php\u300d\u300cException.php\u300d\u300cSMTP.php\u300d\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u3002\u3082\u3057\u304f\u306fsrc\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3054\u3068\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3067\u3082\u826f\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nini_set( 'display_errors', 1 );\r\n\r\nuse PHPMailer\\PHPMailer\\PHPMailer;\r\nuse PHPMailer\\PHPMailer\\Exception;\r\nuse PHPMailer\\PHPMailer\\SMTP;\r\n\r\nrequire('.\/src\/PHPMailer.php');\r\nrequire('.\/src\/Exception.php');\r\nrequire('.\/src\/SMTP.php');\r\n\r\n\/\/ \u6587\u5b57\u30a8\u30f3\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\r\nmb_language('uni');\r\nmb_internal_encoding('UTF-8');\r\n\r\n\/\/ \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\uff08true\u6307\u5b9a\u3067\u4f8b\u5916\u3092\u6709\u52b9\u5316\uff09\r\n$mail = new PHPMailer(true);\r\n\r\ntry {\r\n    \/\/Gmail \u8a8d\u8a3c\u60c5\u5831\r\n    $host = 'smtp.gmail.com';\r\n    $username = 'xxxxxxxxxxxx';\r\n    $password = 'xxxxxxxxxxxx';\r\n\r\n    \/\/\u5dee\u51fa\u4eba\r\n    $from = $username;\r\n    $fromname = $username;\r\n\r\n    \/\/\u5b9b\u5148\r\n    $to = 'xxxxxxxxxxxx';\r\n    $toname = $to;\r\n\r\n    \/\/\u4ef6\u540d\u30fb\u672c\u6587\r\n    $subject = '\u4ef6\u540d';\r\n    $body = '\u672c\u6587';\r\n\r\n    \/\/\u30e1\u30fc\u30eb\u8a2d\u5b9a\r\n    $mail-&gt;SMTPDebug = 2; \/\/\u30c7\u30d0\u30c3\u30b0\u7528\r\n    $mail-&gt;isSMTP();\r\n    $mail-&gt;SMTPAuth = true;\r\n    $mail-&gt;Host = $host;\r\n    $mail-&gt;Username = $username;\r\n    $mail-&gt;Password = $password;\r\n    $mail-&gt;SMTPSecure = 'tls';\r\n    $mail-&gt;Port = 587;\r\n    $mail-&gt;CharSet = \"utf-8\";\r\n    $mail-&gt;Encoding = \"base64\";\r\n    $mail-&gt;setFrom($from, $fromname);\r\n    $mail-&gt;addAddress($to, $toname);\r\n    $mail-&gt;Subject = $subject;\r\n    $mail-&gt;Body        = $body;\r\n\r\n    \/\/\u30e1\u30fc\u30eb\u9001\u4fe1\r\n    $mail-&gt;send();\r\n    echo '\u6210\u529f';\r\n\r\n} catch (Exception $e) {\r\n    echo '\u5931\u6557: ', $mail-&gt;ErrorInfo;\r\n}<\/pre>\n<p>\u4e0a\u8a18\u306fGoogle\u306eSMTP\u7d4c\u7531\u3067\u9001\u4fe1\u3059\u308b\u5f62\u306b\u306a\u308b\u304c\u3001\u4ed6\u306eSMTP\u30b5\u30fc\u30d0\u3092\u7d4c\u7531\u3055\u305b\u305f\u3044\u5834\u5408\u306f\u300chost\u300d\u300cusername\u300d\u300cpassword\u300d\u8fba\u308a\u3092\u9069\u5b9c\u5909\u66f4\u3059\u308b\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30c7\u30d0\u30c3\u30b0\u60c5\u5831\u3092\u8868\u793a\u3057\u306a\u3044\u5834\u5408<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$mail-&gt;SMTPDebug = 0; \/\/\u30c7\u30d0\u30c3\u30b0\u7528<\/pre>\n<p>&nbsp;<\/p>\n<h2>CC\u3082\u3057\u304f\u306fBCC\u3067\u9001\u4fe1\u5148\u3092\u8ffd\u52a0\u3057\u305f\u3044\u5834\u5408<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$mail-&gt;setFrom($from, $fromname);\r\n\r\n\/\/CC\u8ffd\u52a0\r\n$mail-&gt;addCC('xxxxxxxxxx');\r\n\r\n\/\/BCC\u8ffd\u52a0\r\n$mail-&gt;addBCC('xxxxxxxxxx');<\/pre>\n<p>&nbsp;<\/p>\n<h2>Class\u5185\u3067PHPMailer\u3092\u4f7f\u3044\u305f\u3044\u5834\u5408<\/h2>\n<p>\u524d\u8ff0\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u307e\u307eClass\u5185\u3067\u4f7f\u304a\u3046\u3068\u3059\u308b\u3068use\u90e8\u5206\u304c\u4e91\u3005\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3002\u4ee5\u4e0b\u3067\u5bfe\u5fdc\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public static function mailSend()\r\n{\r\n\r\n    require('.\/src\/PHPMailer.php');\r\n    require('.\/src\/Exception.php');\r\n    require('.\/src\/SMTP.php');\r\n\r\n    mb_language('uni');\r\n    mb_internal_encoding('UTF-8');\r\n\r\n    \/\/\u3053\u3053\u306e\u8a18\u8ff0\u306b\u6ce8\u610f\r\n    $mail = new PHPMailer\\PHPMailer\\PHPMailer();\r\n\r\n    \/\/\u4ee5\u964d\u306f\u901a\u5e38\u306e\u4f7f\u3044\u65b9\u3068\u540c\u69d8\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/into-the-program.com\/phpmailer-gmail\/\" target=\"_blank\" rel=\"noopener\">https:\/\/into-the-program.com\/phpmailer-gmail\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u3067\u30e1\u30fc\u30eb\u3092SMTP\u9001\u4fe1\u3057\u305f\u304b\u3063\u305f\u3002\u307e\u305f\u3001\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u3060\u3063\u305f\u306e\u3067Compo ... <\/p>\n","protected":false},"author":1,"featured_media":1085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[90],"class_list":["post-3407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-phpmailer"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=3407"}],"version-history":[{"count":0,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/3407\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1085"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=3407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=3407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=3407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}