2017年5月8日9:10:471.在模塊的配置文件中加入下里面代碼,帳號最好用126郵箱'THINK_EMAIL' => array('SMTP_HOST' => 'smtp.163.com', //SMTP服務器'SMTP_PORT' => '465', //SMTP服務器端口'SMTP_USER' => 'ihtxt@126.com', //SMTP服務器用戶名'SMTP_PASS' => 'ihtxt.com', //SMTP服務器密碼'FROM_EMAIL' => 'wdxy@126.com', //發件人EMAIL'FROM_NAME' => '沃德學院', //發件人名稱'REPLY_EMAIL' => 'wdxy@163.com', //回覆EMAIL(留空則爲發件人EMAIL)'REPLY_NAME' => '沃德學院', //回覆名稱(留空則爲發件人名稱)), 2.在模塊的函數庫中加入下面代碼function think_send_mail($to, $name, $subject = '', $body = '', $attachment = null){$config = C('THINK_EMAIL');vendor('PHPMailer.class#phpmailer'); //從PHPMailer目錄導class.phpmailer.php類文件$mail = new PHPMailer(); //PHPMailer對象$mail->CharSet = 'UTF-8'; //設定郵件編碼,默認ISO-8859-1,若是發中文此項必須設置,不然亂碼$mail->IsSMTP(); // 設定使用SMTP服務$mail->SMTPDebug = 0; // 關閉SMTP調試功能// 1 = errors and messages// 2 = messages only$mail->SMTPAuth = true; // 啓用 SMTP 驗證功能$mail->SMTPSecure = 'ssl'; // 使用安全協議$mail->Host = $config['SMTP_HOST']; // SMTP 服務器$mail->Port = $config['SMTP_PORT']; // SMTP服務器的端口號$mail->Username = $config['SMTP_USER']; // SMTP服務器用戶名$mail->Password = $config['SMTP_PASS']; // SMTP服務器密碼$mail->SetFrom($config['FROM_EMAIL'], $config['FROM_NAME']);$replyEmail = $config['REPLY_EMAIL']?$config['REPLY_EMAIL']:$config['FROM_EMAIL'];$replyName = $config['REPLY_NAME']?$config['REPLY_NAME']:$config['FROM_NAME'];$mail->AddReplyTo($replyEmail, $replyName);$mail->Subject = $subject;$mail->AltBody = "爲了查看該郵件,請切換到支持 HTML 的郵件客戶端"; $mail->MsgHTML($body);$mail->AddAddress($to, $name);if(is_array($attachment)){ // 添加附件foreach ($attachment as $file){is_file($file) && $mail->AddAttachment($file);}}return $mail->Send() ? true : $mail->ErrorInfo;}3.下載mail插件解壓到ThinkPHP/Library/Vendor目錄中,再將PHPMail目錄中的class.smtp.php複製一份到Vendor目錄中並重命名爲SMTP.php4.修改php.int文件windows下在php.ini中去掉下面的分號extension=php_openssl.dll並將allow_url_fopen = Off改成allow_url_fopen = On5.在控制器中使用函數$r = think_send_mail('要發送的郵箱','發送人名稱,即你的名稱','文件標題','郵件內容');