{"id":48693,"date":"2024-12-02T10:00:27","date_gmt":"2024-12-02T02:00:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48693\/"},"modified":"2024-12-02T10:00:27","modified_gmt":"2024-12-02T02:00:27","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%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48693\/","title":{"rendered":"PHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f<\/h1>\n<p><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<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\u600e\u4e48\u529e\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/1730250222672185ee26854.jpg\" class=\"aligncenter\" title=\"PHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"PHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u95ee\u9898<\/strong><\/p>\n<p>php \u5185\u7f6e\u7684 mail() \u51fd\u6570\u53ef\u7528\u4e8e\u5728\u7ebf\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u4e3b\u673a\u7a7a\u95f4\u53ef\u80fd\u4e0d\u652f\u6301\u6b64\u51fd\u6570\uff0c\u5bfc\u81f4\u65e0\u6cd5\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u5982\u95ee\u9898\u7b54\u6848\u6240\u8ff0\uff0cphpmailer \u7c7b\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u5b83\u662f\u4e00\u4e2a\u5e38\u7528\u7684 php \u5e93\uff0c\u4e13\u95e8\u7528\u4e8e\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u4ee5\u4e0b\u6b65\u9aa4\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 phpmailer \u53d1\u9001\u7535\u5b50\u90ae\u4ef6\uff1a<\/p>\n<ol>\n<li>\u5b89\u88c5 phpmailer\uff08\u53ef\u901a\u8fc7 composer \u6216\u624b\u52a8\u4e0b\u8f7d\uff09<\/li>\n<li>\u5305\u542b phpmailer \u548c smtp \u7c7b<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a phpmailer \u5b9e\u4f8b\u5e76\u8bbe\u7f6e\u53d1\u4ef6\u4eba\u3001\u6536\u4ef6\u4eba\u3001\u4e3b\u9898\u548c\u6b63\u6587<\/li>\n<li>\u6839\u636e\u4e3b\u673a\u7a7a\u95f4\u8bbe\u7f6e smtp \u8bbe\u7f6e\uff08\u4f8b\u5982\u4e3b\u673a\u3001\u7aef\u53e3\u548c\u8eab\u4efd\u9a8c\u8bc1\uff09<\/li>\n<li>\u8c03\u7528 send() \u65b9\u6cd5\u53d1\u9001\u7535\u5b50\u90ae\u4ef6<\/li>\n<\/ol>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 phpmailer \u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;?php\nuse PHPMailer\\PHPMailer\\PHPMailer;\nuse PHPMailer\\PHPMailer\\SMTP;\n\n\/\/ \u521b\u5efa PHPMailer \u5b9e\u4f8b\n$mail = new PHPMailer();\n\n\/\/ \u8bbe\u7f6e\u53d1\u4ef6\u4eba\n$mail-&gt;setFrom('your@email.com');\n\n\/\/ \u8bbe\u7f6e\u6536\u4ef6\u4eba\uff08\u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2a\uff09\n$mail-&gt;addAddress('receiver@email.com');\n\n\/\/ \u8bbe\u7f6e\u4e3b\u9898\n$mail-&gt;Subject = '\u6d4b\u8bd5\u7535\u5b50\u90ae\u4ef6';\n\n\/\/ \u8bbe\u7f6e\u6b63\u6587\n$mail-&gt;Body = '\u4f60\u597d\uff0c\u8fd9\u662f\u4e00\u5c01\u6d4b\u8bd5\u7535\u5b50\u90ae\u4ef6\u3002';\n\n\/\/ \u8bbe\u7f6e SMTP \u8bbe\u7f6e\uff08\u5982\u4e3b\u673a\u3001\u7aef\u53e3\u548c\u8eab\u4efd\u9a8c\u8bc1\uff09\n$mail-&gt;isSMTP();\n$mail-&gt;Host = 'smtp.example.com';\n$mail-&gt;Port = 587;\n$mail-&gt;SMTPAuth = true;\n$mail-&gt;SMTPSecure = 'tls';\n$mail-&gt;Username = 'your@email.com';\n$mail-&gt;Password = 'your_password';\n\n\/\/ \u53d1\u9001\u7535\u5b50\u90ae\u4ef6\nif ($mail-&gt;send()) {\n    echo '\u90ae\u4ef6\u53d1\u9001\u6210\u529f';\n} else {\n    echo '\u90ae\u4ef6\u53d1\u9001\u5931\u8d25';\n}<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aPHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f \u6587\u7ae0\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300aPHP \u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u9047\u5230\u95ee\u9898\u600e\u4e48\u529e\uff1f\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01 php\u5728\u7ebf\u53d1\u9001\u90ae\u4ef6\u7684\u95ee\u9898 php \u5185\u7f6e\u7684 mail() \u51fd\u6570\u53ef\u7528\u4e8e\u5728\u7ebf\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u4e3b\u673a\u7a7a\u95f4\u53ef\u80fd\u4e0d\u652f\u6301\u6b64\u51fd\u6570\uff0c\u5bfc\u81f4\u65e0\u6cd5\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002 \u89e3\u51b3\u65b9\u6cd5 \u5982\u95ee\u9898\u7b54\u6848\u6240\u8ff0\uff0cphpmailer \u7c7b\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u5b83\u662f\u4e00\u4e2a\u5e38\u7528\u7684 php \u5e93\uff0c\u4e13\u95e8\u7528\u4e8e\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u4ee5\u4e0b\u6b65\u9aa4\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 phpmailer \u53d1\u9001\u7535\u5b50\u90ae\u4ef6\uff1a \u5b89\u88c5 phpmailer\uff08\u53ef\u901a\u8fc7 composer \u6216\u624b\u52a8\u4e0b\u8f7d\uff09 \u5305\u542b phpmailer \u548c smtp \u7c7b \u521b\u5efa\u4e00\u4e2a phpmailer \u5b9e\u4f8b\u5e76\u8bbe\u7f6e\u53d1\u4ef6\u4eba\u3001\u6536\u4ef6\u4eba\u3001\u4e3b\u9898\u548c\u6b63\u6587 \u6839\u636e\u4e3b\u673a\u7a7a\u95f4\u8bbe\u7f6e smtp \u8bbe\u7f6e\uff08\u4f8b\u5982\u4e3b\u673a\u3001\u7aef\u53e3\u548c\u8eab\u4efd\u9a8c\u8bc1\uff09 \u8c03\u7528 send() \u65b9\u6cd5\u53d1\u9001\u7535\u5b50\u90ae\u4ef6 \u4ee5\u4e0b\u662f\u4f7f\u7528 phpmailer \u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\uff1a &lt;?php use PHPMailer\\PHPMailer\\PHPMailer; use PHPMailer\\PHPMailer\\SMTP; \/\/ \u521b\u5efa PHPMailer \u5b9e\u4f8b $mail = new PHPMailer(); \/\/ \u8bbe\u7f6e\u53d1\u4ef6\u4eba $mail-&gt;setFrom(&#8216;your@email.com&#8217;); \/\/ \u8bbe\u7f6e\u6536\u4ef6\u4eba\uff08\u53ef\u4ee5\u8bbe\u7f6e\u591a\u4e2a\uff09 [&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-48693","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48693","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=48693"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48693\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}