phpmailer的使用方法
生活随笔
收集整理的這篇文章主要介紹了
phpmailer的使用方法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
composer require phpmailer/phpmailer
<?php header('content-type:text/html;charset=utf-8;'); set_time_limit(3600);require "vendor/autoload.php"; $send_res = sendEmail('主題', '內(nèi)容', 'jianlong@123.io');die;// phpmailer 的使用 // sendEmail('主題', '內(nèi)容', '收件郵箱', '附件'); function sendEmail($subject, $contents, $to_email, $attach_file='') {$mail = new PHPMailer\PHPMailer\PHPMailer();$mail->isSMTP();$mail->CharSet = 'utf8'; //設(shè)定郵件編碼$mail->Host = 'smtp.exmail.qq.com'; //SMTP服務(wù)器$mail->SMTPAuth = true;$mail->Username = 'noreply@jianlong.io'; //郵箱用戶名$mail->Password = '密碼或者授權(quán)碼'; //密碼或者授權(quán)碼$mail->SMTPSecure = "ssl";$mail->Port = 465; //服務(wù)器端口 25 或者465 具體要看郵箱服務(wù)器支持$mail->IsHTML(true);$mail->setFrom("noreply@jianlong.io", "jianlong"); //發(fā)件人//$mail->addReplyTo('xxxx@163.com', 'info'); //回復(fù)的時(shí)候回復(fù)給哪個(gè)郵箱 建議和發(fā)件人一致$mail->addAddress($to_email);//$mail->addAddress('ellen@example.com'); // 可添加多個(gè)收件人//$mail->addCC('cc@example.com'); //抄送//$mail->addBCC('bcc@example.com'); //密送if (!empty($attach_file)) {$file_name = basename($attach_file);$mail->AddAttachment($attach_file, $file_name); // 發(fā)送附件并且重命名}$mail->Subject = $subject;$mail->Body = $contents;//$mail->AltBody = '如果郵件客戶端不支持HTML則顯示此內(nèi)容';if (!$mail->send()) {trace($mail->ErrorInfo, 'error');return 0;} else {return 1;} }?
總結(jié)
以上是生活随笔為你收集整理的phpmailer的使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: OSS: cURL error: Emp
- 下一篇: php语音信息,PHP代码示例_PHP语