PHP 郵件傳送

2021-08-06 03:12:21 字數 1401 閱讀 4517

電子郵件的傳送需要遵從特定的協議,常用的電子郵件協議包括smtp、pop3、imap,其中郵件的建立和傳送用smtp協議即可。smtp是****** mail transferprotocol的簡稱,即簡單郵件傳輸協議。

(2)php版本

利用phpmailer來完成php的郵箱傳送:

將其重新命名為phpmailer,並新增到thinkphp的library下的vendor下,如圖:

2、在config.php中新增配置think_email引數:

'think_email' => array(

'smtp_host' => 'smtp.163.com', // smtp 伺服器的位址

'smtp_port' => 25, // smtp 埠

'smtp_secure' => '', // 使用安全協議, '' 或 'ssl' 或 'tls'

'smtp_user' => '[email protected]', // 登入 smtp 的使用者名稱

'smtp_pass' => '********', // 登入 smtp 的密碼

'from_email' => '[email protected]', // 傳送郵件的郵箱

),

3、在function.php中新增函式:

function think_send_mail($to, $subject = '', $body = '', $attachment = null)

}public function index()

if(is_array($attachment))

}return $mail->send() ? true : $mail->errorinfo;

}

4、編寫測試**

public function index()
注意:如果埠號被限制或者網路問題,或者密碼伺服器輸入錯誤,都可能導致如下失敗資訊:

smtp connect() failed.

成功執行的效果如圖所示:

5、成功收到傳送的郵件

php郵件傳送

今天要用到php的郵件傳送,便用phpmailer弄了個 類檔案 emaillclass.php class phpmailer function send addr,fromname,title,content smtp array array ehlo hello lb,220,250 ehlo...

php 郵件傳送

2 修改class.phpmailer.php 增加變數 fromemail 修改下面內容 成如下內容 if this fromname else result this headerline from this fromemail.fromname result this headerline r...

php 傳送郵件

results wpdb query sql 傳送郵件提醒有人申請 smtpserver smtp.qq.com smtp伺服器,如 smtp.qq.com smtpserverport 25 smtp伺服器端口,一般為25 smtpusermail 117 x837 qq.com smtp伺服器的...