• 技术文章 >php教程 >php手册

    PHP 中的类:邮件群发

    2016-06-13 11:20:15原创704
    本类可以用与于email的群发,测试的环境是linux,系统需要安装sendmail才能使用

    if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) {
    define('MAIL_CLASS_DEFINED', 1 );
    class email {
    function email ( $subject, $message, $senderName, $senderEmail, $toList, $ccList=0, $bccList=0, $replyTo=0) {
    $this->sender = $senderName . " <$senderEmail>";
    $this->replyTo = $replyTo;
    $this->subject = $subject;
    $this->message = $message;
    // 定义收件人
    if ( is_array($toList) ) {
    $this->to = join( $toList, "," );
    } else {
    $this->to = $toList;
    }
    // 定义抄送名单
    if ( is_array($ccList) && sizeof($ccList) ) {
    $this->cc = join( $ccList, "," );
    } elseif ( $ccList ) {
    $this->cc = $ccList;
    }
    // 定义密码抄送名单
    if ( is_array($bccList) && sizeof($bccList) ) {
    $this->bcc = join( $bccList, "," );
    } elseif ( $bccList ) {
    $this->bcc = $bccList;
    }
    }
    // 发送函数
    // 利用php中的mail()函数发送email
    function send () {
    //发件人
    $this->headers = "From: " . $this->sender . " ";
    // 回复地址
    if ( $this->replyTo ) {
    $this->headers .= "Reply-To: " . $this->replyTo . " ";
    }
    // 抄送
    if ( $this->cc ) {
    $this->headers .= "Cc: " . $this->cc . " ";
    }
    // 秘密抄送
    if ( $this->bcc ) {
    $this->headers .= "Bcc: " . $this->bcc . " ";
    }
    return mail ( $this->to, $this->subject, $this->message, $this->headers ); //返回结果
    }
    }
    }
    ?>
    说明:
    参数说明
    ----------
    - 以下几个参数是必须的:subject, message, senderName, senderEmail 和 toList
    - 这几个参数则是可选的:ccList, bccList 和 replyTo
    - toList, ccList 和 bccList 必须是有效的email地址

    php入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    上一篇:PHP4 调用自己编写的 COM 组件 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• PHP中SESSION使用中的一点经验总结• 用PHP向数据库中实现简单的增删改查(纯代码,待完善),php增删• WordPress中"无法将上传的文件移动至"错误的解决方法,wordpress解决方法• smarty模板引擎从php中获取数据的方法,smarty模板• php 复杂生成验证码图片
    1/1

    PHP中文网