簡體   English   中英

PHP的SMTP郵件功能

[英]php smtp mail function

我可以使用此功能通過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->from\r\n";
        if($this->html === TRUE) {
            $this->headers.= "MIME-Version: 1.0\r\n";
            $this->headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
        }
    }

    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;
     }

}

我一直在尋找一個簡單的解決方案,但除了Git和我的腳本的一些完全替代品之外,找不到任何(據我所知的php)。

如果要將SMTP郵件配置與mail()函數一起使用,則需要在php.ini設置SMTP配置。

有關詳細信息,請參見電子郵件配置

但是我建議使用第三方庫,例如PHPMailer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM