PHP在线生成excel并发送邮件

PHP在线生成excel并发送邮件

本文实现PHP发送带excel的邮件大致思路如下:首先生成二维数组,并导入到excel文件当中。然后用phpmailer把生成的文件发送到邮件当中。

淘建站为您提供更多_表单代码_输入框_邮件_发送,在此特别感谢您对我们的支持与厚爱!

查看演示

演示不了,点击反馈

加入收藏

下载 384 次

打赏作者

觉得不错,可打赏下作者

下载资源

免费共享

特别说明:本站资源来自网友发布分享,仅供学习与参考,请勿用于商业用途,若有侵权请联系删除(272966172@qq.com)。
分类:表单代码 > 输入框 难易程度:中级

PHP 把二维数组导入到excel,返回参数是生成的文件数组

include_once 'function.php';
$email  = $_POST['email'];
$titles = array("id", "时间", "名称"); //excel 列
$datas = array(
    0 => array(
        "id" => "1",
        "date" => date("Y-m-d", strtotime("-1 day")),
        "name" => "素材圈"
    ),
    1 => array(
        "id" => "2",
        "date" => date("Y-m-d"),
        "name" => "分享微博送30积分"
    ),
);
$file_name = date("Y-m-d") . "素材圈excel发送";
$attachments = sendExcel($file_name, $titles, $datas);

发送生成的文件到指定邮箱

$rs = sendMail($email, "标题测试", "素材圈,欢迎来到素材圈<a href='http://www.sucaiq.com'>http://www.sucaiq.com</a>", $attachments);
echo $rs;

记得在sendMail方法里面配置邮件服务器,最好是企业邮箱,比如QQ企业邮箱,会立即收到。163等普通邮箱发送频繁会被冻结,过段时间又可以发送。

function sendMail($to, $subject, $body = '', $attachment = null) { //$to 收件者 $subject主题 $body 内容  $attachment附件
    $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
    if (!preg_match($pattern, $to)) {
        return "email_error";
    }
    //邮件服务器配置
    $detail = array(
        "smpt" => "smtp.qq.com",
        "account" => "",
        "pwd" => "",
    );

    $title = getGb2312("发送excel到邮箱");
    include_once('phpmailer/class.phpmailer.php');
    $mail = new PHPMailer(); //PHPMailer对象
    $mail->CharSet = 'GB2312'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
    $mail->Encoding = "base64";
    $mail->IsSMTP();  // 设定使用SMTP服务
    $mail->SMTPDebug = 0;                     // 关闭SMTP调试功能
    $mail->SMTPAuth = true;                  // 启用 SMTP 验证功能
    $mail->SMTPSecure = '';                 // 使用安全协议
    $mail->Host = $detail['smpt'];  // SMTP 服务器
    $mail->Port = "25";  // SMTP服务器的端口号
    $mail->Username = $detail['account'];  // SMTP服务器用户名
    $mail->Password = $detail['pwd'];  // SMTP服务器密码
    $mail->Subject = getGb2312($subject); //邮件标题
    $mail->SetFrom($detail['account'], $title);
    $mail->MsgHTML(getGb2312($body));
    $mail->AddAddress(getGb2312($to), $title);

    if (is_array($attachment)) { // 添加附件
        foreach ($attachment as $file) {
            is_file($file) && $mail->AddAttachment($file);
        }
    }
    $rs = $mail->Send() ? true : $mail->ErrorInfo;
    return $rs;
}

声明:本资料由淘建站会员提供,如转载注明来源,资料来源淘建站免费素材库:https://www.taojz.cn/texiao/871.html
PHP在线生成excel并发送邮件 希望对你有帮助,感谢您的支持!
  • CSS3打开信封发送留言样式代码

    CSS3打开信封发送留言样式代码

  • 留言(0)
    头像
     阿里云限量代金券,戳我领取
    1 2