{"id":473,"date":"2014-07-08T02:19:34","date_gmt":"2014-07-08T02:19:34","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=473"},"modified":"2014-07-08T02:19:34","modified_gmt":"2014-07-08T02:19:34","slug":"%e4%bd%bf%e7%94%a8-phpmailer-%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6bak","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/473.html","title":{"rendered":"\u4f7f\u7528 PHPMailer \u53d1\u9001\u90ae\u4ef6[bak]"},"content":{"rendered":"<div style=\"color: #000000;\">PHPMailer \u662f\u4e00\u4e2a\u5f3a\u5927\u7684 PHP \u7f16\u5199\u7684\u90ae\u4ef6\u53d1\u9001\u7c7b\uff0c\u4f7f\u7528\u5b83\u53ef\u4ee5\u66f4\u52a0\u4fbf\u6377\u7684\u53d1\u9001\u90ae\u4ef6\uff0c\u5e76\u4e14\u8fd8\u80fd\u53d1\u9001\u9644\u4ef6\u548c HTML \u683c\u5f0f\u7684\u90ae\u4ef6\uff0c\u540c\u65f6\u8fd8\u80fd\u4f7f\u7528 SMTP \u670d\u52a1\u5668\u6765\u53d1\u9001\u90ae\u4ef6\u3002<\/div>\n<div style=\"color: #000000;\">=<\/div>\n<div style=\"color: #000000;\">\u5927\u5bb6\u4e5f\u8bb8\u4f1a\u95ee\uff0cPHP \u4e0d\u662f\u5df2\u7ecf\u5185\u7f6e\u4e86 mail() \u51fd\u6570\u4e86\u5417\uff0c\u4e3a\u4ec0\u4e48\u8981\u7528 PHPMailer \u5462\uff1f<span style=\"color: #ff0000;\">mail() \u51fd\u6570\u529f\u80fd\u5e76\u4e0d\u5b8c\u5584\uff0c\u53ea\u80fd\u53d1\u9001\u6587\u672c\u7684 email\uff0c\u5e76\u4e14 mail() \u51fd\u6570\u53ea\u80fd\u5e94\u7528\u5728 Linux \u670d\u52a1\u5668<\/span>\uff08\u5f88\u591a\u88c5\u5728 Win \u4e3b\u673a\u7684 WP \u535a\u5ba2\u7528\u6237\u6ce8\u518c\u6536\u4e0d\u5230\u90ae\u4ef6\u4e5f\u662f\u8fd9\u4e2a\u539f\u56e0\uff09\uff0c<span style=\"color: #ff0000;\">\u8fd8\u6709\u4e00\u4e2a\u6700\u5927\u7684\u95ee\u9898\u5c31\u662f\u4f7f\u7528 mail() \u51fd\u6570\u53d1\u9001\u7684\u90ae\u4ef6\u6ca1\u6709\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\uff0c\u5f88\u591a\u90ae\u4ef6\u6536\u4e0d\u5230\u4f7f\u7528 mail() \u51fd\u6570\u53d1\u9001\u7684\u90ae\u4ef6\u6216\u8005\u53d1\u9001\u7684\u90ae\u4ef6\u76f4\u63a5\u8fdb\u5165\u5783\u573e\u90ae\u7bb1<\/span>\u3002<\/div>\n<h6 style=\"color: #000000;\">PHPMailer \u4e3b\u8981\u529f\u80fd<\/h6>\n<div style=\"color: #000000;\">\n<ol>\n<li>\u5728\u90ae\u4ef6\u4e2d\u5305\u542b\u591a\u4e2a TO\u3001CC\u3001BCC \u548c REPLY-TO\u3002<\/li>\n<li>\u5e73\u53f0\u5e94\u7528\u5e7f\u6cdb\uff0c\u652f\u6301\u7684 SMTP \u670d\u52a1\u5668\u5305\u62ec Sendmail\u3001qmail\u3001Postfix\u3001Gmail\u3001Imail\u3001Exchange \u7b49\u7b49\u3002<\/li>\n<li>\u652f\u6301\u5d4c\u5165\u56fe\u50cf\uff0c\u9644\u4ef6\uff0cHTML \u90ae\u4ef6\u3002<\/li>\n<li>\u53ef\u9760\u7684\u5f3a\u5927\u7684\u8c03\u8bd5\u529f\u80fd\u3002<\/li>\n<li>\u652f\u6301 SMTP \u8ba4\u8bc1\u3002<\/li>\n<li>\u81ea\u5b9a\u4e49\u90ae\u4ef6\u5934\u3002<\/li>\n<li>\u652f\u6301 8bit\u3001base64\u3001binary \u548c quoted-printable \u7f16\u7801<\/li>\n<\/ol>\n<h6>PHPMailer \u7684\u7b80\u5355\u4f7f\u7528<\/h6>\n<\/div>\n<div style=\"color: #000000;\">\u8fd9\u91cc\u4f7f\u7528\u6700\u5e38\u7528\u7684 Gmail \u6765\u505a\u4ecb\u7ecd\u3002\u8bf7\u5230\u8fd9\u91cc\u67e5\u770b\u5176\u4ed6<a style=\"color: #6c8c37;\" href=\"http:\/\/blog.wpjam.com\/m\/gmail-qmail-163mail-imap-smtp-pop3\/\" target=\"_blank\">\u5e38\u7528\u90ae\u7bb1\u7684 SMTP \u5730\u5740\u548c\u7aef\u53e3<\/a>\u3002<\/div>\n<div style=\"color: #000000;\">\n<div>\n<pre class=\"lang:php decode:true \">require_once('class.phpmailer.php');\nrequire_once(\"class.smtp.php\");\n$mail\u00a0 = new PHPMailer();\n$mail-&gt;CharSet =\"UTF-8\";\u00a0\u00a0\/\/\u8bbe\u5b9a\u90ae\u4ef6\u7f16\u7801\uff0c\u9ed8\u8ba4ISO-8859-1\uff0c\u5982\u679c\u53d1\u4e2d\u6587\u6b64\u9879\u5fc5\u987b\u8bbe\u7f6e\u4e3a UTF-8\n$mail-&gt;IsSMTP();\u00a0\u00a0\/\/ \u8bbe\u5b9a\u4f7f\u7528SMTP\u670d\u52a1\n$mail-&gt;SMTPAuth\u00a0\u00a0 = true;\u00a0\u00a0\/\/ \u542f\u7528 SMTP \u9a8c\u8bc1\u529f\u80fd\n$mail-&gt;SMTPSecure = \"ssl\";\u00a0\u00a0\/\/ SMTP \u5b89\u5168\u534f\u8bae\n$mail-&gt;Host\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \"smtp.gmail.com\"; \u00a0\/\/ SMTP \u670d\u52a1\u5668\n$mail-&gt;Port\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 465; \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/ SMTP\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7\n$mail-&gt;Username = \"your_name@gmail.com\";\/\/ SMTP\u670d\u52a1\u5668\u7528\u6237\u540d\n$mail-&gt;Password\u00a0\u00a0 = \"your_password\"; \u00a0 \u00a0\/\/ SMTP\u670d\u52a1\u5668\u5bc6\u7801\n$mail-&gt;SetFrom('\u53d1\u4ef6\u4eba\u5730\u5740', '\u53d1\u4ef6\u4eba\u540d\u79f0');\u00a0\u00a0\u00a0 \/\/ \u8bbe\u7f6e\u53d1\u4ef6\u4eba\u5730\u5740\u548c\u540d\u79f0\n$mail-&gt;AddReplyTo(\"\u90ae\u4ef6\u56de\u590d\u4eba\u5730\u5740\",\"\u90ae\u4ef6\u56de\u590d\u4eba\u540d\u79f0\");\u00a0\u00a0\/\/ \u8bbe\u7f6e\u90ae\u4ef6\u56de\u590d\u4eba\u5730\u5740\u548c\u540d\u79f0\n$mail-&gt;Subject\u00a0\u00a0\u00a0 = ''; \/\/ \u8bbe\u7f6e\u90ae\u4ef6\u6807\u9898\n$mail-&gt;AltBody\u00a0\u00a0\u00a0 = \"\u4e3a\u4e86\u67e5\u770b\u8be5\u90ae\u4ef6\uff0c\u8bf7\u5207\u6362\u5230\u652f\u6301 HTML \u7684\u90ae\u4ef6\u5ba2\u6237\u7aef\";\u00a0\u00a0\/\/ \u53ef\u9009\u9879\uff0c\u5411\u4e0b\u517c\u5bb9\u8003\u8651\n$mail-&gt;MsgHTML('');\u00a0\u00a0\/\/ \u8bbe\u7f6e\u90ae\u4ef6\u5185\u5bb9\n$mail-&gt;AddAddress('\u6536\u4ef6\u4eba\u5730\u5740', \"\u6536\u4ef6\u4eba\u540d\u79f0\");\n\/\/$mail-&gt;AddAttachment(\"images\/phpmailer.gif\"); \/\/ \u9644\u4ef6\nif(!$mail-&gt;Send()) {\n\u00a0\u00a0\u00a0 echo \"\u53d1\u9001\u5931\u8d25\uff1a\" . $mail-&gt;ErrorInfo;\n} else {\n\u00a0\u00a0\u00a0 echo \"\u606d\u559c\uff0c\u90ae\u4ef6\u53d1\u9001\u6210\u529f\uff01\";\n}<\/pre>\n<\/div>\n<p>\u4e0b\u8f7d\uff1a<a class=\"external\" style=\"color: #6c8c37;\" href=\"http:\/\/phpmailer.worxware.com\/\" target=\"_blank\">PHPMailer<\/a>\uff0c\u5982\u679c\u662f WordPress \u7528\u6237\uff0c\u5219\u65e0\u9700\u4e0b\u8f7d\uff0c<span style=\"color: #ff0000;\">WordPress \u5df2\u7ecf\u81ea\u5e26 PHPMailer<\/span>\u3002<\/p>\n<div style=\"color: gray;\"><small>\u6765\u6e90\uff1a<a href=\"http:\/\/blog.wpjam.com\/m\/phpmailer\/\" target=\"_blank\">http:\/\/blog.wpjam.com\/m\/phpmailer\/<\/a><\/small><\/div>\n<div style=\"color: gray;\">\n<hr \/>\n<\/div>\n<\/div>\n<h6 style=\"color: #333333;\">PHPMailer\u7684\u4f7f\u7528\uff08\u8fd9\u91cc\u4ee5\u7528gmail smtp\u53d1\u9001\u90ae\u4ef6\u4e3a\u4f8b\uff0c\u5f53\u7136\u4e5f\u652f\u6301sendmail\/pop3 \u7b49\u5176\u4ed6\u65b9\u5f0f\uff09\uff1a<\/h6>\n<ol style=\"color: #333333;\">\n<li>\u9996\u5148\u5230<a style=\"color: #6c8c37;\" title=\"http:\/\/phpmailer.worxware.com\/\" href=\"http:\/\/phpmailer.worxware.com\/\" target=\"_blank\">http:\/\/phpmailer.worxware.com\/<\/a>\u00a0\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u7a0b\u5e8f\u5305<\/li>\n<li>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u627e\u5230class.phpmailer.php\u00a0\u3001class.smtp.php\u4e24\u4e2a\u7c7b\u653e\u5230\u81ea\u5df1\u7684\u76ee\u5f55\u4e0b\uff01<\/li>\n<li>\u7136\u540e\u65b0\u5efa\u4e00\u4e2aphp\u6587\u4ef6\u8fd9\u91cc\u547d\u540d\u4e3a\uff1aphpmail_jiucool.php<\/li>\n<li>phpmail_jiucool.php\u5185\u5bb9\u5982\u4e0b\uff1a<\/li>\n<\/ol>\n<p style=\"color: #333333;\">\u6211\u76f4\u63a5\u5c06\u90ae\u4ef6\u53d1\u9001\u6a21\u5757\u5199\u6210\u4e00\u4e2a\u51fd\u6570sendMail(),\u5927\u5bb6\u4f7f\u7528\u7684\u65f6\u5019\u76f4\u63a5\u8c03\u7528\u8be5\u51fd\u6570\u5373\u53ef,\u51fd\u6570\u5185\u5bb9\u4e3a\uff1a<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\nfunction sendMail($to,$subject = \"\",$body = \"\"){\n    \/\/$to \u8868\u793a\u6536\u4ef6\u4eba\u5730\u5740 $subject \u8868\u793a\u90ae\u4ef6\u6807\u9898 $body\u8868\u793a\u90ae\u4ef6\u6b63\u6587\n    \/\/error_reporting(E_ALL);\n    error_reporting(E_STRICT);\n    date_default_timezone_set(\"Asia\/Shanghai\");\/\/\u8bbe\u5b9a\u65f6\u533a\u4e1c\u516b\u533a\n    require_once('class.phpmailer.php');\n    include(\"class.smtp.php\");\n    $mail = new PHPMailer(); \/\/new\u4e00\u4e2aPHPMailer\u5bf9\u8c61\u51fa\u6765\n    $body = eregi_replace(\"[]\",'',$body); \/\/\u5bf9\u90ae\u4ef6\u5185\u5bb9\u8fdb\u884c\u5fc5\u8981\u7684\u8fc7\u6ee4\n    $mail-&gt;CharSet =\"UTF-8\";\/\/\u8bbe\u5b9a\u90ae\u4ef6\u7f16\u7801\uff0c\u9ed8\u8ba4ISO-8859-1\uff0c\u5982\u679c\u53d1\u4e2d\u6587\u6b64\u9879\u5fc5\u987b\u8bbe\u7f6e\uff0c\u5426\u5219\u4e71\u7801\n    $mail-&gt;IsSMTP(); \/\/ \u8bbe\u5b9a\u4f7f\u7528SMTP\u670d\u52a1\n    $mail-&gt;SMTPDebug  = 1;\t\/\/ \u542f\u7528SMTP\u8c03\u8bd5\u529f\u80fd\n\t\t\t\t\t\t\t\/\/ 1 = errors and messages\n\t\t\t\t\t\t\t\/\/ 2 = messages only\n    $mail-&gt;SMTPAuth   = true;\t\/\/ \u542f\u7528 SMTP \u9a8c\u8bc1\u529f\u80fd\n    $mail-&gt;SMTPSecure = \"ssl\";\t\/\/ \u5b89\u5168\u534f\u8bae\n    $mail-&gt;Host       = \"smtp.googlemail.com\";\t\/\/ SMTP \u670d\u52a1\u5668\n    $mail-&gt;Port       = 465;\t\/\/ SMTP\u670d\u52a1\u5668\u7684\u7aef\u53e3\u53f7\n    $mail-&gt;Username   = \"SMTP\u670d\u52a1\u5668\u7528\u6237\u540d\";\t\/\/ SMTP\u670d\u52a1\u5668\u7528\u6237\u540d\n    $mail-&gt;Password   = \"SMTP\u670d\u52a1\u5668\u5bc6\u7801\";\t\/\/ SMTP\u670d\u52a1\u5668\u5bc6\u7801\n    $mail-&gt;SetFrom('\u53d1\u4ef6\u4eba\u5730\u5740\uff0c\u5982admin#ixyzero.com #\u6362\u6210@', '\u53d1\u4ef6\u4eba\u540d\u79f0');\n    $mail-&gt;AddReplyTo(\"\u90ae\u4ef6\u56de\u590d\u5730\u5740,\u5982admin#ixyzero.com #\u6362\u6210@\",\"\u90ae\u4ef6\u56de\u590d\u4eba\u7684\u540d\u79f0\");\n    $mail-&gt;Subject    = $subject;\n    $mail-&gt;AltBody    = \"To view the message, please use an HTML compatible email viewer! - From http:\/\/ixyzero.com\"; \/\/ optional, comment out and test\n    $mail-&gt;MsgHTML($body);\n    $address = $to;\n    $mail-&gt;AddAddress($address, \"\u6536\u4ef6\u4eba\u540d\u79f0\");\n    \/\/$mail-&gt;AddAttachment(\"images\/phpmailer.gif\");\t\t\t\/\/ attachment\n    \/\/$mail-&gt;AddAttachment(\"images\/phpmailer_mini.gif\");\t\/\/ attachment\n    if(!$mail-&gt;Send()) {\n        echo \"Mailer Error: \" . $mail-&gt;ErrorInfo;\n    } else {\n        echo \"Message sent!\u606d\u559c\uff0c\u90ae\u4ef6\u53d1\u9001\u6210\u529f\uff01\";\n    }\n}<\/pre>\n<div style=\"color: gray;\"><small>\u6765\u6e90\uff1a<a href=\"http:\/\/www.jiucool.com\/phpmailer-php-email\/\" target=\"_blank\">http:\/\/www.jiucool.com\/phpmailer-php-email\/<\/a><\/small><\/div>\n<div style=\"color: gray;\">\n<hr \/>\n<\/div>\n<h6 style=\"color: #000000;\"><\/h6>\n<h6 style=\"color: #000000;\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<div style=\"color: #000000;\">\n<ul>\n<li><a href=\"https:\/\/github.com\/Synchro\/PHPMailer\" target=\"_blank\">https:\/\/github.com\/Synchro\/PHPMailer<\/a><\/li>\n<li><a href=\"http:\/\/p2j.cn\/?p=428\" target=\"_blank\">PHP\u4f7f\u7528PHPMailer\u548c\u8c37\u6b4c\u514d\u8d39SMTP\u53d1\u9001\u90ae\u4ef6<\/a><\/li>\n<li><a href=\"http:\/\/blog.techwheels.net\/send-email-using-wamp-server\/\" target=\"_blank\">Send Email from localhost\/WAMP Server using PHPMailer\/SMTP<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHPMailer \u662f\u4e00\u4e2a\u5f3a\u5927\u7684 PHP \u7f16\u5199\u7684\u90ae\u4ef6\u53d1\u9001\u7c7b\uff0c\u4f7f\u7528\u5b83\u53ef\u4ee5\u66f4\u52a0\u4fbf\u6377\u7684\u53d1\u9001\u90ae\u4ef6\uff0c\u5e76\u4e14\u8fd8\u80fd\u53d1\u9001\u9644\u4ef6\u548c  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12],"tags":[213],"class_list":["post-473","post","type-post","status-publish","format-standard","hentry","category-programing","category-tools","tag-phpmailer"],"views":2274,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=473"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/473\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}