{"id":880,"date":"2022-11-04T19:02:34","date_gmt":"2022-11-04T11:02:34","guid":{"rendered":"http:\/\/www.aqwu.net\/wp\/?p=880"},"modified":"2022-11-05T18:00:36","modified_gmt":"2022-11-05T10:00:36","slug":"php-%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6%ef%bc%8c%e6%94%af%e6%8c%81%e6%96%87%e6%9c%ac%e4%bf%a1%e6%81%af%e5%92%8c%e9%99%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.aqwu.net\/wp\/?p=880","title":{"rendered":"php \u53d1\u9001\u90ae\u4ef6\uff0c\u652f\u6301\u6587\u672c\u4fe1\u606f\u548c\u9644\u4ef6"},"content":{"rendered":"\n<p>\u7cfb\u7edf\u9700\u8981\u5b89\u88c5 sendmail,\u5e76\u542f\u52a8 sendmail \u670d\u52a1<\/p>\n\n\n\n<p>\u5f00\u542fhttpd\u53d1\u9001\u90ae\u4ef6\u652f\u6301:<\/p>\n\n\n\n<p>setsebool -P httpd_can_sendmail 1<\/p>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php\n\/\/ email.class.php, \u53d1\u9001\u90ae\u4ef6\uff0c\u652f\u6301\u6587\u672c\u4fe1\u606f\u548c\u9644\u4ef6\n\nclass CMailMessage\n{\n  var $subject;\n  var $addr_to;\n  var $text_msg;\n  var $text_encoded_files;\n  var $text_tail;\n  var $mime_headers;\n  var $mime_boundary = \"\";\n  var $smtp_headers;\n\n  function CMailMessage($from, $to, $subject, $msg)\n  {\n    $this->mime_boundary = $this->getRandomBoundary(1);\n    $this->subject = \"=?utf-8?B?\" . base64_encode($subject) . \"?=\";\n    $this->addr_to = $to;\n    $this->smtp_headers = $this->write_smtpheaders($from);\n    $this->text_msg = $this->write_msg($msg);\n    $this->mime_headers = $this->write_mimeheaders();\n    $this->text_tail = $this->write_tail();\n    $this->text_encoded_files = \"\";\n  }\n  function getRandomBoundary($offset=0)\n  {\n    srand(time()+$offset);\n    return(\"----==\".strtoupper(md5(rand()))) . \"==_\";\n  }\n\n  function attach_content($contents, $downfilename, $mimetype)\n  {\n    $encoded = chunk_split(base64_encode($contents));\n    $out = \"--\" . $this->mime_boundary . \"\\n\";\n    $out .= \"Content-type: \" . $mimetype . \";\\n\";\n    $out .= \"\tname=\\\"$downfilename\\\";\\n\";\n    $out .= \"Content-Transfer-Encoding: base64\\n\";\n    $out .= \"Content-disposition: attachment;\\n\";\n    $out .= \"\tfilename=\\\"$downfilename\\\"\\n\\n\";\n    $out .= $encoded . \"\\n\";\n    $this->text_encoded_files .= $out;\n  }\n\n  function attach_file($sourcefile,$downfilename,$mimetype)\n  {\n    if (is_readable($sourcefile)) {\n      $fd = fopen($sourcefile, \"r\");\n      $contents = fread($fd, filesize($sourcefile));\n      fclose($fd);\n      $out = $this->attach_content($contents, $downfilename, $mimetype);\n      $this->text_encoded_files .= $out;\n    }\n  }\n\n  function write_smtpheaders($addr_from)\n  {\n    $out = \"From: $addr_from\\n\";\n    $out .= \"Reply-To: $addr_from\\n\";\n    $out .= \"X-Mailer: PHP3\\n\";\n    $out .= \"X-Sender: $addr_from\\n\";\n    return $out;\n  }\n\n  function write_mimeheaders()\n  {\n    $out = \"MIME-version: 1.0\\n\";\n    $out .= \"Content-type: multipart\/alternative;\\n\";\n    $out .= \"\tboundary=\\\"$this->mime_boundary\\\"\\n\";\n    $out .= \"Content-Transfer-Encoding: 8Bit\\n\";\n    $out .= \"This is a multi-part message in MIME format.\\n\";\n    return $out;\n  }\n\n  function write_msg($msgtext)\n  {\n    $out = \"--\" . $this->mime_boundary . \"\\n\";\n    $out .= \"Content-Type: text\/plain;\\n\";\n    $out .= \"\tcharset=\\\"utf-8\\\"\\n\";\n    $out .= \"Content-Transfer-Encoding: base64\\n\\n\";\n    \n    $encoded .= chunk_split(base64_encode($msgtext));\n    $out .= $encoded . \"\\n\";\n    return $out;\n  }\n  function write_tail()\n  {\n    $out = \"--\" . $this->mime_boundary . \"--\\n\";\n    return $out;\n  }\n\n  function sendMessage()\n  {\n    $headers = $this->smtp_headers . $this->mime_headers;\n    $message = $this->text_msg . $this->text_encoded_files . $this->text_tail;\n    var_dump($this->addr_to);\n    var_dump($this->subject);\n    var_dump($headers);\n    var_dump($message);\n\n    mail($this->addr_to, $this->subject, $message, $headers);\n  }\n}\n?>\n<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><strong>\u7b2c1\u79cd\u60c5\u51b5\uff0c\u53ea\u53d1\u9001\u6d88\u606f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php \nrequire_once('email.class.php');\n\n\/\/\u53d1\u4ef6\u4eba\n$from = 'support@aqwu.net';\n\/\/\u6536\u4ef6\u4eba\n$to = 'zhangxj@aqwu.net';\n\/\/\u4e3b\u984c\n$subject = \"test1\";\n\n\n$message = \"\u8fd9\u662f\u4e00\u6761\u4e2d\u6587\u4fe1\u606f\uff0cthis is a english message.\";\n\n$mailMsg = new CMailMessage($from,$to,$subject,$message);\n$mailMsg-&gt;sendMessage();\n\n?&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>\u7b2c2\u79cd\u60c5\u51b5\uff0c\u53d1\u9001\u6d88\u606f\u548c\u6587\u4ef6\uff0c\u6587\u4ef6\u4ee5\u9644\u4ef6\u5f62\u5f0f\u6765\u53d1\u9001<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php \nrequire_once('email.class.php');\n\n\/\/\u53d1\u4ef6\u4eba\n$from = 'support@aqwu.net';\n\/\/\u6536\u4ef6\u4eba\n$to = 'zhangxj@aqwu.net';\n\/\/\u4e3b\u984c\n$subject = \"test2\";\n\n\n$message = \"\u8fd9\u662f\u4e00\u6761\u4e2d\u6587\u4fe1\u606f\uff0cthis is a english message.\";\n$sourcefile = 'test.exe';\n$downfilename = \"test.exe\";\n$mimetype = \"application\/octet-stream\";\n\n$mailMsg = new CMailMessage($from,$to,$subject,$message);\n$mailMsg-&gt;attach_file($sourcefile,$downfilename,$mimetype);\n$mailMsg-&gt;sendMessage();\n\n?&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>\u7b2c3\u79cd\u60c5\u51b5\uff0c\u53d1\u9001\u6d88\u606f\u548c\u5185\u5bb9\uff0c\u5185\u5bb9\u4ee5\u9644\u4ef6\u5f62\u5f0f\u6765\u53d1\u9001<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php \nrequire_once('email.class.php');\n\n\/\/\u53d1\u4ef6\u4eba\n$from = 'support@aqwu.net';\n\/\/\u6536\u4ef6\u4eba\n$to = 'zhangxj@aqwu.net';\n\/\/\u4e3b\u984c\n$subject = \"test3\";\n\n\n$message = \"\u8fd9\u662f\u4e00\u6761\u4e2d\u6587\u4fe1\u606f\uff0cthis is a english message.\";\n$contents = 'this is a test file info';\n$downfilename = \"test.txt\";\n$mimetype = \"application\/octet-stream\";\n\n$mailMsg = new CMailMessage($from,$to,$subject,$message);\n$mailMsg-&gt;attach_content($contents,$downfilename,$mimetype);\n$mailMsg-&gt;sendMessage();\n\n?&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>\u7b2c4\u79cd\u60c5\u51b5\uff0c\u53d1\u9001\u6d88\u606f\u548c\u591a\u4e2a\u6587\u4ef6\u548c\u591a\u4e2a\u5185\u5bb9\uff0c\u6587\u4ef6\u548c\u5185\u5bb9\u5747\u4ee5\u9644\u4ef6\u5f62\u5f0f\u6765\u53d1\u9001<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;?php \nrequire_once('email.class.php');\n\n\/\/\u53d1\u4ef6\u4eba\n$from = 'support@aqwu.net';\n\/\/\u6536\u4ef6\u4eba\n$to = 'zhangxj@aqwu.net';\n\/\/\u4e3b\u984c\n$subject = \"test4\";\n\n\n$message = \"\u8fd9\u662f\u4e00\u6761\u4e2d\u6587\u4fe1\u606f\uff0cthis is a english message.\";\n$contents = 'this is a test file info';\n$downfilename = \"test.txt\";\n$mimetype = \"application\/octet-stream\";\n\n$mailMsg = new CMailMessage($from,$to,$subject,$message);\n$mailMsg-&gt;attach_content($contents,$downfilename,$mimetype);\n\n$sourcefile = 'test.exe';\n$downfilename = \"test.exe\";\n$mimetype = \"application\/octet-stream\";\n$mailMsg-&gt;attach_file($sourcefile,$downfilename,$mimetype);\n\n$mailMsg-&gt;sendMessage();\n\n?&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7cfb\u7edf\u9700\u8981\u5b89\u88c5 sendmail,\u5e76\u542f\u52a8 sendmail \u670d\u52a1 \u5f00\u542fhttpd\u53d1\u9001\u90ae\u4ef6\u652f\u6301: setseboo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43],"tags":[60,196,195],"class_list":["post-880","post","type-post","status-publish","format-standard","hentry","category-infoarticle","tag-linux","tag-mail","tag-sendmail"],"views":994,"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=880"}],"version-history":[{"count":11,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/880\/revisions"}],"predecessor-version":[{"id":904,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/880\/revisions\/904"}],"wp:attachment":[{"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqwu.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}