{"id":736,"date":"2023-07-18T16:18:33","date_gmt":"2023-07-18T07:18:33","guid":{"rendered":"https:\/\/blog.mydepot.kr\/?p=736"},"modified":"2023-07-18T16:18:34","modified_gmt":"2023-07-18T07:18:34","slug":"php-phpmailer%eb%a5%bc-%ec%9d%b4%ec%9a%a9%ed%95%b4%ec%84%9c-%ec%9d%b4%eb%a9%94%ec%9d%bc-%eb%b3%b4%eb%82%b4%ea%b8%b0-%eb%8b%a4%ec%9d%8c-%ec%b9%b4%ec%b9%b4%ec%98%a4","status":"publish","type":"post","link":"https:\/\/blog.mydepot.kr\/?p=736","title":{"rendered":"[PHP] PHPMailer\ub97c \uc774\uc6a9\ud574\uc11c \uc774\uba54\uc77c \ubcf4\ub0b4\uae30 (\ub2e4\uc74c \uce74\uce74\uc624)"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfunction sendEmailSMTP($subject = &#039;\uc774\uba54\uc77c \uc81c\ubaa9&#039;, $fromEmail = &#039;your_email@example.com&#039;, $fromName = &#039;\ubcf4\ub0b4\ub294 \uc0ac\ub78c&#039;, $toRecipients, $message, $signature = &quot;&quot;)\n{\n      $mail = new PHPMailer(true);\n\n      try {\n            \/\/ \uc11c\ubc84 \uc124\uc815\n            $mail-&gt;isSMTP();\n            $mail-&gt;Host = &#039;smtp.daum.net&#039;; \/\/ SMTP \uc11c\ubc84 \uc8fc\uc18c\n            $mail-&gt;Port = 465; \/\/ SMTP \ud3ec\ud2b8 \ubc88\ud638\n            $mail-&gt;SMTPAuth = true;\n            $mail-&gt;Username = &#039;admin&#039;; \/\/ SMTP \uacc4\uc815\n            $mail-&gt;Password = &#039;password&#039;; \/\/ SMTP \uacc4\uc815 \ube44\ubc00\ubc88\ud638\n            $mail-&gt;SMTPSecure = &#039;ssl&#039;;\n            $mail-&gt;CharSet = &#039;utf-8&#039;;\n            $mail-&gt;Encoding = &quot;base64&quot;;\n\n            \/\/ \ubc1c\uc2e0\uc790 \uc124\uc815\n            $mail-&gt;setFrom($fromEmail, $fromName);\n\n            \/\/ \uc218\uc2e0\uc790 \uc124\uc815\n            if (count($toRecipients) &gt; 1) {\n                  \/\/ \uc5ec\ub7ec \uc218\uc2e0\uc790\uc5d0\uac8c \ubcf4\ub0bc \ub54c\ub294 \uc228\uc740 \ucc38\uc870(BCC) \uc0ac\uc6a9\n                  foreach ($toRecipients as $recipient) {\n                        $toEmail = $recipient&#x5B;&#039;email&#039;];\n                        $toName = isset($recipient&#x5B;&#039;name&#039;]) ? $recipient&#x5B;&#039;name&#039;] : $toEmail;\n                        $mail-&gt;addBCC($toEmail, $toName);\n                  }\n\n                  $mail-&gt;addAddress($fromEmail, &quot;\ub2e8\uccb4\uba54\uc77c \uc218\uc2e0\uc790&quot;);\n            } else {\n                  \/\/ \ub2e8\uc77c \uc218\uc2e0\uc790\uc5d0\uac8c \ubcf4\ub0bc \ub54c\ub294 \uc77c\ubc18\uc801\uc778 \uc218\uc2e0\uc790(CC) \uc0ac\uc6a9\n                  $toEmail = $toRecipients&#x5B;0]&#x5B;&#039;email&#039;];\n                  $toName = isset($toRecipients&#x5B;0]&#x5B;&#039;name&#039;]) ? $toRecipients&#x5B;0]&#x5B;&#039;name&#039;] : $toEmail;\n                  $mail-&gt;addAddress($toEmail, $toName);\n\n                  $mail-&gt;addBCC($toEmail, &quot;\ubc1c\uc2e0\uba54\uc77c \uc800\uc7a5&quot;);\n            }\n\n            \/\/ \uc774\uba54\uc77c \ub0b4\uc6a9 \uc124\uc815\n            $mail-&gt;isHTML(true);\n            $mail-&gt;Subject = $subject;\n\n            $sendMessage = $message;\n            if ($signature !== &quot;&quot;) {\n                  $sendMessage = &quot;{$message}&amp;lt;br&gt;{$signature}&quot;;\n            }\n            $mail-&gt;Body = $sendMessage;\n\n            \/\/ \uc774\uba54\uc77c \ubcf4\ub0b4\uae30\n            $mail-&gt;send();\n            echo &#039;\uc774\uba54\uc77c\uc774 \uc131\uacf5\uc801\uc73c\ub85c \ubcf4\ub0b4\uc84c\uc2b5\ub2c8\ub2e4.&#039;;\n      } catch (Exception $e) {\n            echo &#039;\uc774\uba54\uc77c \ubcf4\ub0b4\uae30 \uc2e4\ud328\ud588\uc2b5\ub2c8\ub2e4. \uc5d0\ub7ec: &#039; . $mail-&gt;ErrorInfo;\n      }\n}\n<\/pre><\/div>\n\n\n<p>\ucc38\uace0\uc0ac\ud56d<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SMTP \uc544\uc774\ub514\ub294 \ub2e4\uc74c \uc544\uc774\ub514, \ube44\ubc00\ubc88\ud638\ub294 \ub2e4\uc74c \ube44\ubc00\ubc88\ud638\ub97c \uc0ac\uc6a9\ud55c\ub2e4.<\/li>\n\n\n\n<li>\ub2e8, 2\ucc28 \ub85c\uadf8\uc778\uc774 \uc124\uc815\ub418\uc5b4 \uc788\uc744 \uacbd\uc6b0\uc5d0\ub294 \uc571 \ube44\ubc00\ubc88\ud638\ub97c \uc124\uc815\ud558\uc5ec \ub300\uc2e0 \uc0ac\uc6a9\ud55c\ub2e4.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\ucc38\uace0\uc0ac\ud56d<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[8],"tags":[23,382,383,384,385],"class_list":["post-736","post","type-post","status-publish","format-standard","hentry","category-php","tag-php","tag-382","tag-383","tag-384","tag-phpmailer"],"modified_by":"\ucc38\ube5b\ubc14\ub2e4","_links":{"self":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=736"}],"version-history":[{"count":1,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/736\/revisions"}],"predecessor-version":[{"id":737,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=\/wp\/v2\/posts\/736\/revisions\/737"}],"wp:attachment":[{"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mydepot.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}