在這裡我要介紹的是如何使用smtp進行發送郵件,分别介紹了普通連結和ssl連結兩種方式。
一、準備材料
smtp類下載下傳位址:https://download.csdn.net/download/panjiapengfly/10688054
二、代碼實作
簡單粗暴,上代碼:
<?php
header("Content-Type: text/html; charset=utf-8");
require_once("email.class.php");
/**
* 以騰訊企業郵箱為例子(賬戶:[email protected] 密碼:j8sssHGAesacqDYdR)
*
* @author pjp
*/
//不使用ssl連結方式發送郵件
$smtpServer="smtp.exmail.qq.com"; //SMTP伺服器(一般都是在自己郵箱設定的地方,可看到)
$smtpServerPort="25"; //SMTP伺服器端口
$smtpUserMail="[email protected]"; //SMTP伺服器使用者郵箱
$mailTo="[email protected],[email protected]"; //收件人郵箱(多個可以使用逗号隔開,)
$user="[email protected]"; //SMTP伺服器使用者郵箱
$mailPwd="j8sssHGAesacqDYdR"; //SMTP伺服器使用者密碼
$mailTitle="郵箱标題";
$mailContent='<h1>測試郵件 001</h1>';
//使用ssl連結方式發送郵件
$smtpServer="ssl://smtp.exmail.qq.com";
$smtpServerPort="465";
$smtpUserMail="[email protected]";
$mailTo="[email protected],[email protected]";
$user="[email protected]";
$mailPwd="j8sssHGAesacqDYdR";
$mailTitle="郵箱标題";
$mailContent='<h1>測試郵件 001</h1>';
// 郵件格式 (HTML/TXT)
$mailType="HTML";
// true表示是否身份驗證
$smtp=new \smtp($smtpServer,$smtpServerPort,true,$user,$mailPwd);
// 是否顯示調試資訊
$smtp->debug=true;
// 傳回 bool
$state=$smtp->sendmail($mailTo,$smtpUserMail,$mailTitle,$mailContent,$mailType);
var_dump($state);