PHP SMTP 邮件功能



我可以让这个函数通过SMTP发送电子邮件吗?

    function send()
{
    if(mail($this->to, $this->subject, $this->body, $this->headers)) return         TRUE;
    else return FALSE;
}

这是以下代码的一部分:

    class sendMail
    {
    var $to;
    var $cc;
    var $bcc;
    var $subject;
    var $from;
    var $headers;
    var $html;
    function sendMail()
    {
        $this->to       = "test@mail.com";
    #$this->to       = "test@test.com";
        $this->cc       = NULL;
        $this->bcc      = NULL;
        $this->subject  = NULL;
        $this->from     = NULL;
        $this->headers  = NULL;
        $this->html     = FALSE;
    }
    function getParams($params)
    {
        $i = 0;
        foreach ($params as $key => $value) {
            switch($key) {
                case 'Submit':
                    NULL;
                break;
                default:
                        if ($key == 'email')
                        {
                        $this->from     = $value;
                        $this->subject  ="Contactgegevens from " . $value . " at www.webandeve.nl ";
                     }
                    $this->body[$i]["key"]     = str_replace("_", " ", ucWords(strToLower($key)));
                    $this->body[$i++]["value"] = $value;
            }
        }
    }
    function setHeaders()
    {
        $this->headers = "From: $this->fromrn";
        if($this->html === TRUE) {
            $this->headers.= "MIME-Version: 1.0rn";
            $this->headers.= "Content-type: text/html; charset=iso-8859-1rn";
        }
    }
    function parseBody()
    {
        $count = count($this->body);
        for($i = 0; $i < $count; $i++) {
            if($this->html) $content.= "<b>";
            $content .= $this->body[$i]["key"].': ';
            if($this->html) $content.= "</b>";
            if($this->html) $content .= nl2br($this->body[$i]["value"])."n";
            else $content .= $this->body[$i]["value"];
            if($this->html) $content.= "<br>n";
            else $content.= "n".str_repeat("-", 80)."n";
        }
        if($this->html) {
            $content = "
            <style>
                BODY {
                  font-family: verdana;
                  font-size: 10;
                }
            </style>
            ".$content;
        }
        $this->body = $content;
    }
    function send()
    {
        if(mail($this->to, $this->subject, $this->body, $this->headers)) return TRUE;
        else return FALSE;
    }
    function set($key, $value)
    {
        if($value) $this->$key = $value;
        else unset($this->$key);
    }
    function get_location()
    {
        return header('Location: thankyou.htm');break;
     }
}

我一直在寻找一个简单的解决方案,但找不到任何(就我对 php 的了解而言),但 Git 和我的脚本的一些完整替代品。

如果要

将SMTP邮件配置与mail()功能一起使用,则需要在php.ini中设置SMTP配置。

有关详细信息,请参阅电子邮件配置。

但是,我建议使用第三方库,例如PHPMailer。

最新更新