您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP系统邮件发送函数

2024/12/20 1:03:48发布17次查看
/** * 功能:系统邮件发送函数 * @param string $to 接收邮件者邮箱 * @param string $name 接收邮件者名称 * @param string $subject 邮件主题 * @param string $body 邮件内容 * @param string $attachment 附件列表 * @return boolean */ function send_mail($to, $name, $subject = '', $body = '', $attachment = null, $config = '') { $config = is_array($config) ? $config : c('system_email'); import('phpmailer.phpmailer', vendor_path); //从phpmailer目录导class.phpmailer.php类文件 $mail = new phpmailer(); //phpmailer对象 $mail->charset = 'utf-8'; //设定邮件编码,默认iso-8859-1,如果发中文此项必须设置,否则乱码 $mail->issmtp(); // 设定使用smtp服务 // $mail->ishtml(true); $mail->smtpdebug = 0; // 关闭smtp调试功能 1 = errors and messages2 = messages only $mail->smtpauth = true; // 启用 smtp 验证功能 if ($config['smtp_port'] == 465) $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['reply_email']; $replyname = $config['reply_name'] ? $config['reply_name'] : $config['reply_name']; $mail->addreplyto($replyemail, $replyname); $mail->subject = $subject; $mail->msghtml($body); $mail->addaddress($to, $name); if (is_array($attachment)) { // 添加附件 foreach ($attachment as $file) { if (is_array($file)) { is_file($file['path']) && $mail->addattachment($file['path'], $file['name']); } else { is_file($file) && $mail->addattachment($file); } } } else { is_file($attachment) && $mail->addattachment($attachment); } return $mail->send() ? true : $mail->errorinfo; }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product