{"id":48715,"date":"2024-12-02T15:25:43","date_gmt":"2024-12-02T07:25:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48715\/"},"modified":"2024-12-02T15:25:43","modified_gmt":"2024-12-02T07:25:43","slug":"php%e5%9c%a8%e7%ba%bf%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%e9%81%87%e5%88%b0%e9%97%ae%e9%a2%98%ef%bc%9a%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3mail%e5%87%bd%e6%95%b0%e6%97%a0%e6%b3%95%e5%8f%91%e9%80%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48715\/","title":{"rendered":"PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302628186721b7229b39c.jpg\" class=\"aligncenter\" title=\"PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f\u63d2\u56fe\" alt=\"PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u7684\u95ee\u9898<\/strong><\/p>\n<p>php\u5185\u5efa\u7684mail()\u51fd\u6570\u867d\u7136\u63d0\u4f9b\u4e86\u53d1\u9001\u90ae\u4ef6\u7684\u57fa\u7840\u80fd\u529b\uff0c\u4f46\u7531\u4e8e\u67d0\u4e9b\u4e3b\u673a\u7a7a\u95f4\u4e0d\u652f\u6301\uff0c\u5bfc\u81f4\u7ecf\u5e38\u51fa\u73b0\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6848\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528phpmailer\u7c7b\u5e93\uff1a<\/strong> phpmailer\u662f\u4e00\u4e2a\u6d41\u884c\u7684php\u90ae\u4ef6\u53d1\u9001\u7c7b\u5e93\uff0c\u652f\u6301\u5e7f\u6cdb\u7684\u4e3b\u673a\u7a7a\u95f4\u3002\u901a\u8fc7\u5f15\u5165phpmailer\uff0c\u53ef\u4ee5\u7ed5\u8fc7mail()\u51fd\u6570\u7684\u9650\u5236\uff0c\u8f7b\u677e\u5b9e\u73b0\u90ae\u4ef6\u53d1\u9001\u3002<\/li>\n<\/ul>\n<pre>use PHPMailer\\PHPMailer\\PHPMailer;\nuse PHPMailer\\PHPMailer\\SMTP;\n\n\/\/ \u5b9e\u4f8b\u5316PHPMailer\u5bf9\u8c61\n$mail = new PHPMailer(true);\n\n\/\/ \u8bbe\u7f6e\u90ae\u4ef6\u53d1\u9001\u670d\u52a1\u5668\n$mail-&gt;isSMTP();\n$mail-&gt;Host       = 'smtp.example.com';\n$mail-&gt;SMTPAuth   = true;\n$mail-&gt;Username   = 'user@example.com';\n$mail-&gt;Password   = 'password';\n$mail-&gt;SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;\n$mail-&gt;Port       = 465;\n\n\/\/ \u8bbe\u7f6e\u90ae\u4ef6\u6536\u4ef6\u4eba\u3001\u53d1\u4ef6\u4eba\u3001\u4e3b\u9898\u548c\u5185\u5bb9\n$mail-&gt;addAddress('recipient@example.com');\n$mail-&gt;setFrom('sender@example.com');\n$mail-&gt;Subject = 'Test Email';\n$mail-&gt;Body    = 'This is a test email.';\n\n\/\/ \u53d1\u9001\u90ae\u4ef6\nif ($mail-&gt;send()) {\n    echo 'Email sent successfully using PHPMailer.';\n} else {\n    echo 'Error: ' . $mail-&gt;ErrorInfo;\n}<\/pre>\n<p>\u91c7\u7528phpmailer\u7c7b\u5e93\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u90ae\u4ef6\u53d1\u9001\u7684\u7ec6\u8282\uff0c\u4f8b\u5982\u53d1\u9001\u670d\u52a1\u5668\u3001\u53d1\u4ef6\u4eba\u548c\u52a0\u5bc6\u534f\u8bae\uff0c\u5e76\u63d0\u4f9b\u66f4\u4e30\u5bcc\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u300aPHP\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3mail()\u51fd\u6570\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\uff1f\u300b\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01 php\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u7684\u95ee\u9898 php\u5185\u5efa\u7684mail()\u51fd\u6570\u867d\u7136\u63d0\u4f9b\u4e86\u53d1\u9001\u90ae\u4ef6\u7684\u57fa\u7840\u80fd\u529b\uff0c\u4f46\u7531\u4e8e\u67d0\u4e9b\u4e3b\u673a\u7a7a\u95f4\u4e0d\u652f\u6301\uff0c\u5bfc\u81f4\u7ecf\u5e38\u51fa\u73b0\u65e0\u6cd5\u53d1\u9001\u90ae\u4ef6\u7684\u95ee\u9898\u3002 \u89e3\u51b3\u65b9\u6848 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6848\uff1a \u4f7f\u7528phpmailer\u7c7b\u5e93\uff1a phpmailer\u662f\u4e00\u4e2a\u6d41\u884c\u7684php\u90ae\u4ef6\u53d1\u9001\u7c7b\u5e93\uff0c\u652f\u6301\u5e7f\u6cdb\u7684\u4e3b\u673a\u7a7a\u95f4\u3002\u901a\u8fc7\u5f15\u5165phpmailer\uff0c\u53ef\u4ee5\u7ed5\u8fc7mail()\u51fd\u6570\u7684\u9650\u5236\uff0c\u8f7b\u677e\u5b9e\u73b0\u90ae\u4ef6\u53d1\u9001\u3002 use PHPMailer\\PHPMailer\\PHPMailer; use PHPMailer\\PHPMailer\\SMTP; \/\/ \u5b9e\u4f8b\u5316PHPMailer\u5bf9\u8c61 $mail = new PHPMailer(true); \/\/ \u8bbe\u7f6e\u90ae\u4ef6\u53d1\u9001\u670d\u52a1\u5668 $mail-&gt;isSMTP(); $mail-&gt;Host = &#8216;smtp.example.com&#8217;; $mail-&gt;SMTPAuth = true; $mail-&gt;Username = &#8216;user@example.com&#8217;; $mail-&gt;Password = &#8216;password&#8217;; $mail-&gt;SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; $mail-&gt;Port = 465; \/\/ \u8bbe\u7f6e\u90ae\u4ef6\u6536\u4ef6\u4eba\u3001\u53d1\u4ef6\u4eba\u3001\u4e3b\u9898\u548c\u5185\u5bb9 $mail-&gt;addAddress(&#8216;recipient@example.com&#8217;); $mail-&gt;setFrom(&#8216;sender@example.com&#8217;); $mail-&gt;Subject = &#8216;Test Email&#8217;; $mail-&gt;Body = &#8216;This is a test email.&#8217;; \/\/ [&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-48715","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48715","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=48715"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48715\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}