{"id":49214,"date":"2024-12-02T09:47:23","date_gmt":"2024-12-02T01:47:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49214\/"},"modified":"2024-12-02T09:47:23","modified_gmt":"2024-12-02T01:47:23","slug":"php%e5%9c%a8%e7%ba%bf%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%e7%9a%84%e9%9a%be%e7%82%b9%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88mail%e5%87%bd%e6%95%b0%e4%b8%8d%e8%83%bd%e6%bb%a1%e8%b6%b3%e9%9c%80%e6%b1%82","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49214\/","title":{"rendered":"PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aPHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241117\/17318470046739e35ccbbde.jpg\" class=\"aligncenter\" title=\"PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f\u63d2\u56fe\" alt=\"PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u96be\u70b9<\/strong><\/p>\n<p>php\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684mail()\u51fd\u6570\uff0c\u7528\u4e8e\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u7136\u800c\uff0c\u8bb8\u591a\u6258\u7ba1\u670d\u52a1\u4e0d\u652f\u6301\u6b64\u51fd\u6570\uff0c\u5bfc\u81f4\u5728\u5728\u7ebf\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u65f6\u9047\u5230\u95ee\u9898\u3002<\/p>\n<p><strong>\u95ee\u9898\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4e24\u79cd\u5e38\u89c1\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p><strong>\u4f7f\u7528phpmailer\u7c7b<\/strong><\/p>\n<p>phpmailer\u662f\u4e00\u4e2aphp\u7c7b\uff0c\u63d0\u4f9b\u4e86\u6bd4mail()\u51fd\u6570\u66f4\u5168\u9762\u7684\u7535\u5b50\u90ae\u4ef6\u53d1\u9001\u529f\u80fd\u3002\u5b83\u5141\u8bb8\u60a8\u81ea\u5b9a\u4e49\u90ae\u4ef6\u5934\u3001\u6dfb\u52a0\u9644\u4ef6\u3001\u4f7f\u7528smtp\u8ba4\u8bc1\u7b49\u3002<\/p>\n<p><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u7535\u5b50\u90ae\u4ef6\u670d\u52a1<\/strong><\/p>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u7535\u5b50\u90ae\u4ef6\u670d\u52a1\uff0c\u5982sendgrid\u3001mailgun\u6216amazon ses\uff0c\u6765\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u8fd9\u4e9b\u670d\u52a1\u63d0\u4f9b\u4e86\u53ef\u9760\u4e14\u53ef\u5b9a\u5236\u7684\u7535\u5b50\u90ae\u4ef6\u53d1\u9001\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528phpmailer\u7c7b\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u6f14\u793a\u4ee3\u7801\uff1a<\/p>\n<pre>use PHPMailer\\PHPMailer\\PHPMailer;\nuse PHPMailer\\PHPMailer\\SMTP;\nuse PHPMailer\\PHPMailer\\Exception;\n\n\/\/Load Composer's autoloader\nrequire 'vendor\/autoload.php';\n\n\/\/Instantiation and passing `true` enables exceptions\n$mail = new PHPMailer(true);\n\ntry {\n    \/\/Server settings\n    $mail-&gt;SMTPDebug = SMTP::DEBUG_SERVER;                      \/\/Enable verbose debug output\n    $mail-&gt;isSMTP();                                            \/\/Send using SMTP\n    $mail-&gt;Host       = 'smtp.example.com';                     \/\/Set the SMTP server to send through\n    $mail-&gt;SMTPAuth   = true;                                   \/\/Enable SMTP authentication\n    $mail-&gt;Username   = 'username@example.com';                  \/\/SMTP username\n    $mail-&gt;Password   = 'secret';                               \/\/SMTP password\n    $mail-&gt;SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         \/\/Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted\n    $mail-&gt;Port       = 587;                                    \/\/TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above\n\n    \/\/Recipients\n    $mail-&gt;setFrom('from@example.com', 'Mailer');\n    $mail-&gt;addAddress('joe@example.net', 'Joe User');     \/\/Add a recipient\n    $mail-&gt;addAddress('ellen@example.com');               \/\/Name is optional\n\n    \/\/Content\n    $mail-&gt;isHTML(true);                                  \/\/Set email format to HTML\n    $mail-&gt;Subject = 'Here is the subject';\n    $mail-&gt;Body    = 'This is the HTML message body &lt;b&gt;in bold!&lt;\/b&gt;';\n    $mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';\n\n    $mail-&gt;send();\n    echo 'Message has been sent';\n} catch (Exception $e) {\n    echo \"Message could not be sent. Mailer Error: {$mail-&gt;ErrorInfo}\";\n}\n?&gt;<\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528phpmailer\u7c7b\uff0c\u60a8\u53ef\u4ee5\u65e0\u7f1d\u5730\u5728\u7ebf\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\uff0c\u800c\u65e0\u9700\u62c5\u5fc3\u6258\u7ba1\u670d\u52a1\u7684\u95ee\u9898\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aPHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aPHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u96be\u70b9\uff1a\u4e3a\u4ec0\u4e48mail()\u51fd\u6570\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b php\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u96be\u70b9 php\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684mail()\u51fd\u6570\uff0c\u7528\u4e8e\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u7136\u800c\uff0c\u8bb8\u591a\u6258\u7ba1\u670d\u52a1\u4e0d\u652f\u6301\u6b64\u51fd\u6570\uff0c\u5bfc\u81f4\u5728\u5728\u7ebf\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u65f6\u9047\u5230\u95ee\u9898\u3002 \u95ee\u9898\u89e3\u51b3\u65b9\u6848 \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u6709\u4e24\u79cd\u5e38\u89c1\u7684\u89e3\u51b3\u65b9\u6848\uff1a \u4f7f\u7528phpmailer\u7c7b phpmailer\u662f\u4e00\u4e2aphp\u7c7b\uff0c\u63d0\u4f9b\u4e86\u6bd4mail()\u51fd\u6570\u66f4\u5168\u9762\u7684\u7535\u5b50\u90ae\u4ef6\u53d1\u9001\u529f\u80fd\u3002\u5b83\u5141\u8bb8\u60a8\u81ea\u5b9a\u4e49\u90ae\u4ef6\u5934\u3001\u6dfb\u52a0\u9644\u4ef6\u3001\u4f7f\u7528smtp\u8ba4\u8bc1\u7b49\u3002 \u4f7f\u7528\u7b2c\u4e09\u65b9\u7535\u5b50\u90ae\u4ef6\u670d\u52a1 \u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u7535\u5b50\u90ae\u4ef6\u670d\u52a1\uff0c\u5982sendgrid\u3001mailgun\u6216amazon ses\uff0c\u6765\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u8fd9\u4e9b\u670d\u52a1\u63d0\u4f9b\u4e86\u53ef\u9760\u4e14\u53ef\u5b9a\u5236\u7684\u7535\u5b50\u90ae\u4ef6\u53d1\u9001\u89e3\u51b3\u65b9\u6848\u3002 \u4ee5\u4e0b\u662f\u4f7f\u7528phpmailer\u7c7b\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u6f14\u793a\u4ee3\u7801\uff1a use PHPMailer\\PHPMailer\\PHPMailer; use PHPMailer\\PHPMailer\\SMTP; use PHPMailer\\PHPMailer\\Exception; \/\/Load Composer&#8217;s autoloader require &#8216;vendor\/autoload.php&#8217;; \/\/Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true); try { \/\/Server settings $mail-&gt;SMTPDebug = SMTP::DEBUG_SERVER; \/\/Enable verbose debug output $mail-&gt;isSMTP(); \/\/Send using SMTP $mail-&gt;Host = &#8216;smtp.example.com&#8217;; \/\/Set the SMTP server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49214","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49214"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49214\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}