{"id":812,"date":"2023-06-01T17:42:20","date_gmt":"2023-06-01T09:42:20","guid":{"rendered":"http:\/\/blog.nonot.cn\/?p=812"},"modified":"2024-07-08T15:29:54","modified_gmt":"2024-07-08T07:29:54","slug":"%e9%98%bf%e9%87%8c%e4%ba%91phpmail%e9%82%ae%e7%ae%b1%e5%8f%91%e9%80%81","status":"publish","type":"post","link":"https:\/\/blog.nonot.cn\/index.php\/2023\/06\/01\/%e9%98%bf%e9%87%8c%e4%ba%91phpmail%e9%82%ae%e7%ae%b1%e5%8f%91%e9%80%81\/","title":{"rendered":"\u963f\u91cc\u4e91phpmail\u90ae\u7bb1\u53d1\u9001"},"content":{"rendered":"<p>\u56e0\u4e3a\u963f\u91cc\u7981\u752825\u7aef\u53e3\uff0c\u91c7\u7528465\u52a0\u5bc6\u7aef\u53e3\uff0c\u9700\u8981\u52a0\u4e0a\u8fd9\u53e5$mail-&gt;SMTPSecure = &#8216;ssl&#8217;;<\/p>\n<p>function emailTo($user,$code){<br \/>\n\/\/\u5f15\u5165PHPMailer\u7684\u6838\u5fc3\u6587\u4ef6<br \/>\ninclude_once &#8216;.\/class.phpmailer.php&#8217;;<br \/>\ninclude_once &#8216;.\/class.smtp.php&#8217;;<\/p>\n<p>\/\/\u5b9e\u4f8b\u5316PHPMailer\u6838\u5fc3\u7c7b<br \/>\n$mail = new PHPMailer();<\/p>\n<p>\/\/$mail-&gt;SMTPDebug = 1;<br \/>\n\/\/\u662f\u5426\u542f\u7528smtp\u7684debug\u8fdb\u884c\u8c03\u8bd5<\/p>\n<p>$mail-&gt;isSMTP();<br \/>\n\/\/\u4f7f\u7528smtp\u9274\u6743\u65b9\u5f0f\u53d1\u9001\u90ae\u4ef6<\/p>\n<p>$mail-&gt;SMTPAuth = true;<br \/>\n\/\/smtp\u9700\u8981\u9274\u6743 \u8fd9\u4e2a\u5fc5\u987b\u662ftrue<\/p>\n<p>$mail-&gt;Host = &#8216;smtp.qq.com&#8217;;<br \/>\n\/\/\u94fe\u63a5qq\u57df\u540d\u90ae\u7bb1\u7684\u670d\u52a1\u5668\u5730\u5740<\/p>\n<p>$mail-&gt;SMTPSecure = &#8216;ssl&#8217;;<br \/>\n\/\/\u8bbe\u7f6e\u4f7f\u7528ssl\u52a0\u5bc6\u65b9\u5f0f\u767b\u5f55\u9274\u6743<\/p>\n<p>$mail-&gt;Port = 465;<br \/>\n\/\/\u8bbe\u7f6essl\u8fde\u63a5smtp\u670d\u52a1\u5668\u7684\u8fdc\u7a0b\u670d\u52a1\u5668\u7aef\u53e3\u53f7<\/p>\n<p>$mail-&gt;CharSet = &#8216;UTF-8&#8217;;<br \/>\n\/\/\u8bbe\u7f6e\u53d1\u9001\u7684\u90ae\u4ef6\u7684\u7f16\u7801<\/p>\n<p>$mail-&gt;FromName = &#8216;XXX&#8217;;<br \/>\n\/\/\u8bbe\u7f6e\u53d1\u4ef6\u4eba\u6635\u79f0<\/p>\n<p>$mail-&gt;Username = &#8216;456@qq.com&#8217;;<br \/>\n\/\/smtp\u767b\u5f55\u7684\u8d26\u53f7<\/p>\n<p>$mail-&gt;Password = &#8216;asdfssdfsdf&#8217;;<br \/>\n\/\/smtp\u767b\u5f55\u7684\u5bc6\u7801 \u4f7f\u7528\u751f\u6210\u7684\u6388\u6743\u780116\u4f4d<\/p>\n<p>$mail-&gt;From = &#8216;456@qq.com&#8217;;<br \/>\n\/\/\u8bbe\u7f6e\u53d1\u4ef6\u4eba\u90ae\u7bb1\u5730\u5740 \u540c\u767b\u5f55\u8d26\u53f7<\/p>\n<p>$mail-&gt;isHTML(true);<br \/>\n\/\/\u90ae\u4ef6\u6b63\u6587\u662f\u5426\u4e3ahtml\u7f16\u7801<\/p>\n<p>$mail-&gt;addAddress($user);<br \/>\n\/\/\u8bbe\u7f6e\u6536\u4ef6\u4eba\u90ae\u7bb1\u5730\u5740\uff0c\u8981\u53d1\u9001\u591a\u4e2a\u5219\u591a\u6b21\u8c03\u7528\u65b9\u6cd5\u5373\u53ef<\/p>\n<p>$mail-&gt;Subject = &#8216;XXX&#8217;;<br \/>\n\/\/\u6dfb\u52a0\u8be5\u90ae\u4ef6\u7684\u4e3b\u9898<\/p>\n<p>$mail-&gt;Body = &#8220;XXX&#8221;;<br \/>\n\/\/\u6dfb\u52a0\u90ae\u4ef6\u6b63\u6587<\/p>\n<p>\/\/\u53d1\u9001\u90ae\u4ef6 \u8fd4\u56de\u72b6\u6001<br \/>\nreturn $mail-&gt;send();<br \/>\n}<br \/>\nvar_dump(emailTo(&#8216;123@qq.com&#8217;,&#8217;123&#8242;));<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u4e3a\u963f\u91cc\u7981\u752825\u7aef\u53e3\uff0c\u91c7\u7528465\u52a0\u5bc6\u7aef\u53e3\uff0c\u9700\u8981\u52a0\u4e0a\u8fd9\u53e5$ma&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/comments?post=812"}],"version-history":[{"count":1,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":1288,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/posts\/812\/revisions\/1288"}],"wp:attachment":[{"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/media?parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/categories?post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nonot.cn\/index.php\/wp-json\/wp\/v2\/tags?post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}