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