{"id":13704286,"url":"https://github.com/weiyixi/PhpMail-SMTP-POP3-IMAP","last_synced_at":"2025-05-05T09:33:31.382Z","repository":{"id":40442365,"uuid":"146682957","full_name":"weiyixi/PhpMail-SMTP-POP3-IMAP","owner":"weiyixi","description":"邮件接收发送  PHP Mail receiving and sending (PHP POP3 IMAP SMTP)","archived":false,"fork":false,"pushed_at":"2024-07-26T06:28:24.000Z","size":117,"stargazers_count":34,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-13T11:38:42.514Z","etag":null,"topics":["imap-client","imap-mailbox","php","pop3-client","smtp-client","smtp-mail"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weiyixi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-30T02:10:49.000Z","updated_at":"2024-07-26T06:28:28.000Z","dependencies_parsed_at":"2024-07-26T07:45:45.124Z","dependency_job_id":"f0390f68-bb87-4cfc-b3e5-8af903d461c7","html_url":"https://github.com/weiyixi/PhpMail-SMTP-POP3-IMAP","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weiyixi%2FPhpMail-SMTP-POP3-IMAP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weiyixi%2FPhpMail-SMTP-POP3-IMAP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weiyixi%2FPhpMail-SMTP-POP3-IMAP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weiyixi%2FPhpMail-SMTP-POP3-IMAP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weiyixi","download_url":"https://codeload.github.com/weiyixi/PhpMail-SMTP-POP3-IMAP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252471716,"owners_count":21753236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["imap-client","imap-mailbox","php","pop3-client","smtp-client","smtp-mail"],"created_at":"2024-08-02T21:01:06.994Z","updated_at":"2025-05-05T09:33:30.998Z","avatar_url":"https://github.com/weiyixi.png","language":"PHP","funding_links":[],"categories":["目录"],"sub_categories":["电子邮件 Email"],"readme":"### PhpMail-SMTP-POP3-IMAP 邮件接收发送  Mail receiving and sending\n   最近遇到一个工程需要自动发件（SMTP）收件(IMAP/POP3)功能,发现很难找到一个PHP的完整包来使用\u003cbr/\u003e\n所以自己综合phpMailer，PhpImap，csdn博客等各开源代码，做一个收发件都包括的工程，供新人使用。\u003cbr/\u003e\n   有不足之处请指出\n\n## imap 收件示例\n\trequire_once __DIR__ . '/src/__autoload.php';\n\tset_time_limit(0);\n\t//IMAP收件\n\t//argument is the directory into which attachments are to be saved:\n\t$mailbox = new \\src\\PhpImap\\Mailbox('{imap.qq.com:993/imap/ssl}INBOX', 'XXXXXXX@qq.com', 'XXXXXXX', __DIR__);\n\t//读取所有邮件id到数组:\n\t//Read all messaged into an array:\n\t$mailsIds = $mailbox-\u003esearchMailbox('ALL');\n\tif (!$mailsIds) {\n\t    die('Mailbox is empty');\n\t}\n\t// Get the first message and save its attachment(s) to disk:\n\t//获取一份邮件对象 打印出来\n\t$mail = $mailbox-\u003egetMail($mailsIds[0]);\n\tvar_dump($mail);\n\tdie;\n## pop3 收件示例\n\trequire_once __DIR__ . '/src/__autoload.php';\n\tset_time_limit(0);\n    \n    $host = \"tls://pop.126.com\"; //‘tls：//’为ssl协议加密，端口走加密端口\n    $user = \"XXXXXX@126.com\"; //邮箱\n    $pass = \"XXXXXX\"; //密码\n    $rec = new \\src\\pop3\\Pop3($host, 995, 3);\n    //打开连接\n    if (!$rec-\u003eopen())\n        die($rec-\u003eerr_str);\n    echo \"open \";\n    //登录\n    if (!$rec-\u003elogin($user, $pass)) {\n        var_dump($rec-\u003eerr_str);\n        die;\n    }\n    echo \"login\";\n    \n    if (!$rec-\u003estat())\n        die($rec-\u003eerr_str);\n    echo \"You  have\" . $rec-\u003emessages . \"emails,total size:\" . $rec-\u003esize . \"\u003cbr\u003e\";\n    if ($rec-\u003emessages \u003e 0) {\n        //读取邮件列表\n        if (!$rec-\u003elistmail())\n            die($rec-\u003eerr_str);\n        echo \"Your mail list：\u003cbr\u003e\";\n        for ($i = 1; $i \u003c= count($rec-\u003email_list); $i++) {\n            echo \"mailId:\" . $rec-\u003email_list[$i]['num'] . \"Size：\" . $rec-\u003email_list[$i]['size'] . \"\u003cBR\u003e\";\n        }\n        //获取一个邮件\n        //read One email\n        $rec-\u003egetmail(1);\n        echo \"getHeader：\u003cbr\u003e\";\n        for ($i = 0; $i \u003c count($rec-\u003ehead); $i++) {\n            echo htmlspecialchars($rec-\u003ehead[$i]) . \"\u003cbr\u003e\\n\";\n        }\n    \n        echo \"getContent：\u003cBR\u003e\";\n        for ($i = 0; $i \u003c count($rec-\u003ebody); $i++) {\n            echo htmlspecialchars($rec-\u003ebody[$i]) . \"\u003cbr\u003e\\n\";\n        }\n    }\n    $rec-\u003eclose();\n    \n    die;\n## SMTP 发件\n\n   \n\trequire_once __DIR__ . '/src/__autoload.php';\n\tset_time_limit(0);\n\n\t/**\n\t * @param $sendto_email  收件地址\n\t * @param $sendto_name   收件人\n\t * @param $subject       邮件标题\n\t * @param $body          邮件内容\n\t * @param $user_name     送件人\n\t * @param $post_array =[\n\t *          'server_address'=\u003e'smtp.qq.com',    //smtp  服务器\n\t *          'port'=\u003e465,                        //端口\n\t *          'mail_id'=\u003e'AAAA@qq.com',          //账号\n\t *          'mail_pwd'=\u003e'密码',                   //密码\n\t *          'mail_address'=\u003e'发件人邮箱'\n\t * ]\n\t * @return bool\n\t * @throws \\src\\PHPMailer\\Exception\n\t */\n\tvar_dump(smtp_mail('XXXXXX@qq.com', 'XXXX', 'hahah', 'aaaaaa', 'XXX', [\n\t\t'server_address' =\u003e 'smtp.126.com',    //smtp  服务器\n\t\t'port' =\u003e 465,                        //端口\n\t\t'mail_id' =\u003e 'XXXXX@126.com',          //账号\n\t\t'mail_pwd' =\u003e 'XXXXX',                   //密码\n\t\t'mail_address' =\u003e 'XXXXXX@126.com'\n\t]));\n\tfunction smtp_mail($sendto_email, $sendto_name, $subject, $body, $user_name, $post_array,$is_html=false)\n\t{\n\t\t$mail = new \\src\\PHPMailer\\PHPMailer();\n\t\t$mail-\u003eSMTPDebug = 0;   // 开启Debug\n\t\t$mail-\u003eIsSMTP();                // 使用SMTP模式发送新建\n\t\t$mail-\u003eHost = $post_array['server_address']; // QQ企业邮箱SMTP服务器地址\n\t\t$mail-\u003ePort = $post_array['port'];  //邮件发送端口，一定是465\n\t\t$mail-\u003eSMTPAuth = true;         // 打开SMTP认证，本地搭建的也许不会需要这个参数\n\t\t$mail-\u003eSMTPSecure = \"ssl\";  // 打开SSL加密，这一句一定要\n\t\t$mail-\u003eUsername = $post_array['mail_id'];   // SMTP用户名\n\t\t$mail-\u003ePassword = $post_array['mail_pwd'];        // 为QQ邮箱SMTP的独立密码，即授权码\n\t\t$mail-\u003eFrom = $post_array['mail_address'];      // 发件人邮箱\n\t\t$mail-\u003eFromName = $user_name;// $post_array['mail_address'];  // 发件人\n\n\t\t$mail-\u003eCharSet = \"UTF-8\";            // 这里指定字符集！\n\t\t$mail-\u003eEncoding = \"base64\";\n\t\tif (!$mail-\u003eAddAddress($sendto_email, $sendto_name)) {\n\t\t\treturn false;\n\t\t}  // 收件人邮箱和姓名\n\t\t$mail-\u003eaddCC($post_array['mail_address']);//抄送\n\t\t$mail-\u003eIsHTML($is_html);  // send as HTML\n\t\t// 邮件主题\n\t\t$mail-\u003eSubject = $subject;\n\n\t\t$mail-\u003eBody = $body;      //isHTML是true 的时候  这里body有效\n\t\t$mail-\u003eAltBody = str_replace(\"\u003cbr/\u003e\", \"\\r\\n\", $body);  //isHTML是false 的时候  这里body有效\n\t\tif (!$mail-\u003eSend()) {\n\t\t\treturn false;\n\t\t} else {\n\t\t\treturn true;\n\t\t}\n\t}\n    \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweiyixi%2FPhpMail-SMTP-POP3-IMAP","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweiyixi%2FPhpMail-SMTP-POP3-IMAP","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweiyixi%2FPhpMail-SMTP-POP3-IMAP/lists"}