时间:2021-07-01 10:21:17 帮助过:22人阅读
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=".$filename.".xls");
header("Pragma: no-cache");
header("Expires: 0");
if (!empty($title)){
foreach ($title as $k => $v) {
$title[$k]=iconv("UTF-8", "GB2312",$v);
}
$title= implode("\t", $title);
echo "$title\n";
}
if (!empty($data)){
foreach($data as $key=>$val){
foreach ($val as $ck => $cv) {
$data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
}
$data[$key]=implode("\t", $data[$key]);
}
echo implode("\n",$data);
}
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = '';
$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->MsgHTML($body);
$mail->AddAddress($to, $name);
if(is_file($attachment)){ // 添加附件
$mail->AddAttachment($attachment);
}
return $mail->Send()