PHP mail sending class library PHPMailer extension using demo

Keywords: PHP network

Installation and use of PHPMailer class library

Download PHPMailer class library and use demo:

Address: https://download.csdn.net/download/fenqing666/10681461

Preconditions:

First: remove the following two semicolons from php.ini
                ;extension=php_sockets.dll
                ;extension=php_openssl.dll

And restart the PHP server to check whether the two services are turned on.

Second: prepare an email account that can relax your email

For example: wolfwangluo@163.com

There are examples of how to use the demo above.

Mailing Code:

/**
     * Send mail
     * @param $user_mail
     * @param $title
     * @param $content
     * @return bool
     * @throws src\Exception
     */
    public function send($user_mail , $title, $content)
    {
        $mail = new PHPMailer(true);

        $mail->IsSMTP();
        $mail->CharSet ="UTF-8";//Code
        $mail->Debugoutput = 'html';// Support for HTML format
        $mail->Host = $this->Host;//HOST address
        $mail->Port = $this->Port;//port
        $mail->SMTPAuth = true;
        $mail->Username = $this->Username;//User name
        $mail->Password = $this->Password;//Password
        $mail->SetFrom($this->FromNum, 'WOLF');//Sender address, sender name
        $mail->AddAddress($user_mail);//delivery address
        if (!empty($type)) {
            $mail->AddAttachment($type,''); // Add attachment and specify name
        }
        $mail->Subject = $title;//Mail title
        $str = "<h3>This message comes from<a href='http://Www.wofuwl. Com '> Wofu network technology < / a >: < H3 > ";
        $str .= $content;
        $mail->MsgHTML($str);
        if ($mail->Send()){
            return true;
        }else{
            return $mail->errorMessage();
        }
    }

Special note: when the class library is referenced into the framework, the namespace should be adjusted according to the current framework

Posted by reddymade on Sat, 28 Dec 2019 10:54:47 -0800