{"id":59303,"date":"2023-10-28T10:42:40","date_gmt":"2023-10-28T02:42:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=59303"},"modified":"2023-10-28T15:20:27","modified_gmt":"2023-10-28T07:20:27","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8swoole%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%8d%8f%e7%a8%8b%e5%ae%9e%e7%8e%b0%e9%ab%98%e5%b9%b6%e5%8f%91%e7%9a%84swoole_smtp%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/59303.html","title":{"rendered":"\u5982\u4f55\u5728Swoole\u4e2d\u4f7f\u7528\u534f\u7a0b\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684swoole_smtp\u51fd\u6570"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u200b\u4f7f\u7528Swoole\u7684\u534f\u7a0b\u529f\u80fd\u53ef\u4ee5\u9ad8\u6548\u5730\u5904\u7406\u5927\u91cf\u7684\u5e76\u53d1\u8bf7\u6c42\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Swoole\u4e2d\u901a\u8fc7\u534f\u7a0b\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684swoole_smtp\u51fd\u6570\u3002\u6211\u4eec\u5c06\u4f9d\u6b21\u63a2\u8ba8\uff1a1.\u4ec0\u4e48\u662fSwoole\u548c\u534f\u7a0b\uff1b2.swoole_smtp\u51fd\u6570\u7684\u57fa\u7840\u77e5\u8bc6\uff1b3.\u534f\u7a0b\u5982\u4f55\u589e\u5f3aswoole_smtp\u7684\u5e76\u53d1\u6027\u80fd\uff1b4.\u5177\u4f53\u7684\u5b9e\u73b0\u6b65\u9aa4\uff1b5.\u5b9e\u8df5\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u4ec0\u4e48\u662fSwoole\u548c\u534f\u7a0b<\/h2>\n\n\n\n<p>Swoole\u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684PHP\u5f02\u6b65\u7f16\u7a0b\u6846\u67b6\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u7f16\u5199\u9ad8\u5e76\u53d1\u3001\u9ad8\u6027\u80fd\u7684\u540e\u7aef\u5f02\u6b65\u4efb\u52a1\u3001\u7f51\u7edc\u670d\u52a1\u7b49\u3002\u534f\u7a0b\u5219\u662fSwoole\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u7279\u6027\uff0c\u5b83\u53ef\u4ee5\u4f7f\u4ee3\u7801\u5f02\u6b65\u6267\u884c\uff0c\u800c\u65e0\u9700\u590d\u6742\u7684\u56de\u8c03\u6216Promise\u7ed3\u6784\uff0c\u4f7f\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u66f4\u6613\u8bfb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.swoole_smtp\u51fd\u6570\u7684\u57fa\u7840\u77e5\u8bc6<\/h2>\n\n\n\n<p>swoole_smtp\u51fd\u6570\u662f\u7528\u4e8e\u5728Swoole\u4e2d\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u7684\u529f\u80fd\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u4f7f\u7528SMTP\u534f\u8bae\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\uff0c\u800c\u65e0\u9700\u4f9d\u8d56\u5176\u4ed6PHP\u6269\u5c55\u6216\u7b2c\u4e09\u65b9\u5e93\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u534f\u7a0b\u5982\u4f55\u589e\u5f3a<\/h2>\n\n\n\n<p>swoole_smtp\u7684\u5e76\u53d1\u6027\u80fd \u4f7f\u7528\u534f\u7a0b\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u540c\u65f6\u53d1\u9001\u591a\u4e2a\u7535\u5b50\u90ae\u4ef6\uff0c\u800c\u4e0d\u662f\u9010\u4e00\u53d1\u9001\u3002\u5f53\u4e00\u4e2a\u90ae\u4ef6\u6b63\u5728\u53d1\u9001\u65f6\uff0c\u5176\u4ed6\u90ae\u4ef6\u53ef\u4ee5\u5728\u540e\u53f0\u5f02\u6b65\u51c6\u5907\u53d1\u9001\uff0c\u4ece\u800c\u5927\u5927\u63d0\u9ad8\u4e86\u90ae\u4ef6\u53d1\u9001\u7684\u5e76\u53d1\u6027\u80fd\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u5177\u4f53\u7684\u5b9e\u73b0\u6b65\u9aa4<\/h2>\n\n\n\n<p>\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Swoole\u6269\u5c55\u5e76\u542f\u7528\u4e86\u534f\u7a0b\u529f\u80fd\u3002\u63a5\u7740\uff0c\u53ef\u4ee5\u4f7f\u7528Swoole\u7684\u534f\u7a0b\u5ba2\u6237\u7aef\u521b\u5efa\u4e00\u4e2aSMTP\u5ba2\u6237\u7aef\uff0c\u5e76\u4f7f\u7528swoole_smtp\u51fd\u6570\u53d1\u9001\u90ae\u4ef6\u3002\u4e3a\u4e86\u5b9e\u73b0\u9ad8\u5e76\u53d1\uff0c\u9700\u8981\u521b\u5efa\u591a\u4e2a\u534f\u7a0b\uff0c\u5e76\u5728\u6bcf\u4e2a\u534f\u7a0b\u4e2d\u53d1\u9001\u90ae\u4ef6\u3002\u4f7f\u7528Swoole\u7684\u534f\u7a0b\u8c03\u5ea6\u529f\u80fd\uff0c\u53ef\u4ee5\u786e\u4fdd\u6240\u6709\u90ae\u4ef6\u90fd\u5f02\u6b65\u53d1\u9001\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u5e76\u53d1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php use Swoole\\Coroutine; Coroutine::create(function () { \/\/ \u521b\u5efaSMTP\u5ba2\u6237\u7aef\u5e76\u8bbe\u7f6e\u670d\u52a1\u5668\u5730\u5740\u548c\u7aef\u53e3 $client = new Swoole\\Coroutine\\Client(SWOOLE_SOCK_TCP); $client-&gt;connect('smtp.server.com', 25); \/\/ \u8bbe\u7f6eSMTP\u534f\u8bae\u76f8\u5173\u4fe1\u606f $client-&gt;send(\"HELO server.com\\r\\n\"); \/\/ ... \u5176\u4ed6SMTP\u547d\u4ee4 \/\/ \u4f7f\u7528swoole_smtp\u53d1\u9001\u90ae\u4ef6 swoole_smtp($client, $m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>lContent); $client-&gt;close(); }); ?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5.\u5b9e\u8df5\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<p>\u5c3d\u7ba1\u4f7f\u7528\u534f\u7a0b\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u90ae\u4ef6\u53d1\u9001\u7684\u5e76\u53d1\u6027\u80fd\uff0c\u4f46\u4ecd\u7136\u9700\u8981\u6ce8\u610f\u51e0\u4e2a\u5173\u952e\u70b9\uff1a<\/p>\n\n\n\n<ul>\n<li>\u786e\u4fddSMTP\u670d\u52a1\u5668\u53ef\u4ee5\u5904\u7406\u5927\u91cf\u7684\u5e76\u53d1\u8fde\u63a5\u3002<\/li>\n\n\n\n<li>\u907f\u514d\u9891\u7e41\u5730\u53d1\u9001\u5927\u91cf\u90ae\u4ef6\uff0c\u4ee5\u9632\u6b62\u88abSMTP\u670d\u52a1\u5668\u5217\u4e3a\u5783\u573e\u90ae\u4ef6\u3002<\/li>\n\n\n\n<li>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u9002\u5f53\u7684\u9519\u8bef\u5904\u7406\u903b\u8f91\uff0c\u4ee5\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684\u4efb\u4f55\u9519\u8bef\u6216\u5f02\u5e38\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u603b\u7ed3\uff1aSwoole\u7684\u534f\u7a0b\u529f\u80fd\u4e3aPHP\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4f7f\u5176\u80fd\u591f\u8f7b\u677e\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684\u540e\u7aef\u670d\u52a1\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u534f\u7a0b\u548cswoole_smtp\u51fd\u6570\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u9ad8\u6548\u3001\u7a33\u5b9a\u5730\u53d1\u9001\u5927\u91cf\u7684\u7535\u5b50\u90ae\u4ef6\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"484\" height=\"300\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u5728\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u7ba1\u7406\u5b57\u4f53-61.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-59304\" \/><\/figure><\/div>\n\n\n<p><strong>\u5e38\u89c1\u95ee\u7b54\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> \u4e3a\u4ec0\u4e48\u9700\u8981\u5728Swoole\u4e2d\u4f7f\u7528\u534f\u7a0b\u6765\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684<strong>swoole_smtp<\/strong>\u51fd\u6570\uff1f<\/li>\n\n\n\n<li><strong>\u7b54\uff1a<\/strong> \u4f7f\u7528Swoole\u7684\u534f\u7a0b\u53ef\u4ee5\u6709\u6548\u5730\u6539\u5584I\/O\u7b49\u5f85\u7684\u95ee\u9898\uff0c\u5b9e\u73b0\u771f\u6b63\u7684\u5e76\u53d1\u64cd\u4f5c\u3002\u5f53\u5728\u53d1\u9001\u90ae\u4ef6\u6216\u4e0eSMTP\u670d\u52a1\u5668\u8fdb\u884c\u4ea4\u4e92\u65f6\uff0c\u534f\u7a0b\u53ef\u4ee5\u786e\u4fdd\u5176\u4ed6\u4efb\u52a1\u4e0d\u4f1a\u88ab\u963b\u585e\uff0c\u4ece\u800c\u5927\u5927\u63d0\u9ad8\u5e94\u7528\u7684\u54cd\u5e94\u901f\u5ea6\u548c\u5e76\u53d1\u80fd\u529b\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> Swoole\u4e2d\u7684\u534f\u7a0b\u4e0e\u4f20\u7edf\u7684PHP\u5f02\u6b65\u7f16\u7a0b\u6709\u4f55\u4e0d\u540c\uff1f<\/li>\n\n\n\n<li><strong>\u7b54\uff1a<\/strong> \u4f20\u7edf\u7684PHP\u5f02\u6b65\u7f16\u7a0b\u4f9d\u8d56\u4e8e\u56de\u8c03\u51fd\u6570\u6765\u5904\u7406\u5f02\u6b65\u4efb\u52a1\uff0c\u8fd9\u5f80\u5f80\u4f1a\u5bfc\u81f4\u4ee3\u7801\u7ed3\u6784\u53d8\u5f97\u590d\u6742\u4e14\u96be\u4ee5\u7ef4\u62a4\u3002\u800cSwoole\u7684\u534f\u7a0b\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u4e3a\u76f4\u89c2\u7684\u7f16\u7a0b\u6a21\u578b\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u4ee5\u540c\u6b65\u7684\u65b9\u5f0f\u7f16\u5199\u4ee3\u7801\uff0c\u4f46\u5728\u8fd0\u884c\u65f6\u5b9e\u73b0\u5f02\u6b65\u7684\u6548\u679c\uff0c\u4f7f\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u548c\u9ad8\u6548\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> \u5982\u4f55\u786e\u4fdd\u5728\u4f7f\u7528\u534f\u7a0b\u5b9e\u73b0<strong>swoole_smtp<\/strong>\u51fd\u6570\u65f6\u7684\u6570\u636e\u5b89\u5168\u6027\uff1f<\/li>\n\n\n\n<li><strong>\u7b54\uff1a<\/strong> \u5f53\u4f7f\u7528\u534f\u7a0b\u8fdb\u884c\u5e76\u53d1\u64cd\u4f5c\u65f6\uff0c\u52a1\u5fc5\u786e\u4fdd\u6bcf\u4e2a\u534f\u7a0b\u5185\u7684\u6570\u636e\u662f\u72ec\u7acb\u7684\uff0c\u907f\u514d\u5168\u5c40\u53d8\u91cf\u6216\u5171\u4eab\u8d44\u6e90\u7684\u4f7f\u7528\uff0c\u4ee5\u9632\u6b62\u6570\u636e\u51b2\u7a81\u6216\u7ade\u4e89\u6761\u4ef6\u3002\u6b64\u5916\uff0c\u5229\u7528Swoole\u63d0\u4f9b\u7684\u5e76\u53d1\u5de5\u5177\u548c\u540c\u6b65\u539f\u8bed\uff0c\u5982Channel\u6216Mutex\u7b49\uff0c\u6765\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee\uff1a<\/strong> \u5728\u4f7f\u7528\u534f\u7a0b\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684<strong>swoole_smtp<\/strong>\u51fd\u6570\u65f6\uff0c\u662f\u5426\u6709\u53ef\u80fd\u51fa\u73b0\u90ae\u4ef6\u53d1\u9001\u5931\u8d25\u7684\u60c5\u51b5\uff1f&nbsp;<strong>\u7b54\uff1a<\/strong> \u662f\u7684\u3002\u4efb\u4f55\u4e0e\u7f51\u7edc\u4ea4\u4e92\u7684\u64cd\u4f5c\u90fd\u6709\u53ef\u80fd\u51fa\u73b0\u5931\u8d25\u6216\u5ef6\u8fdf\u3002\u4e3a\u6b64\uff0c\u5efa\u8bae\u5b9e\u73b0\u91cd\u8bd5\u673a\u5236\uff0c\u5e76\u8bbe\u7f6e\u5408\u7406\u7684\u8d85\u65f6\u65f6\u95f4\u3002\u540c\u65f6\uff0c\u53ef\u4ee5\u5229\u7528Swoole\u7684\u4e8b\u4ef6\u76d1\u542c\u673a\u5236\uff0c\u5bf9SMTP\u7684\u8fde\u63a5\u548c\u54cd\u5e94\u8fdb\u884c\u76d1\u63a7\uff0c\u786e\u4fdd\u90ae\u4ef6\u53d1\u9001\u7684\u7a33\u5b9a\u6027\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u200b\u4f7f\u7528Swoole\u7684\u534f\u7a0b\u529f\u80fd\u53ef\u4ee5\u9ad8\u6548\u5730\u5904\u7406\u5927\u91cf\u7684\u5e76\u53d1\u8bf7\u6c42\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Swoole\u4e2d\u901a\u8fc7\u534f\u7a0b\u5b9e\u73b0\u9ad8\u5e76\u53d1\u7684 [&hellip;]","protected":false},"author":7,"featured_media":59304,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/59303"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=59303"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/59303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/59304"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=59303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=59303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=59303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}