Share - Gửi Mail Bằng Thư Viện PHPMailer | Gextend - Forums

Gextend
  • Home
  • Forums New posts Search forums
  • Resources Latest reviews Search resources
  • Members Current visitors New profile posts Search profile posts
  • What's new Featured content New posts New resources New profile posts Latest activity
Log in Register What's new Search

Search

Everywhere Threads This forum This thread Search titles only Note By: Search Advanced search…
  • New posts
  • Search forums
Menu Log in Register Install the app Install How to install the app on iOS

Follow along with the video below to see how to install our site as a web app on your home screen.

Note: This feature may not be available in some browsers.

  • Home
  • Forums
  • Discussion
  • Web
  • PHP
You are using an out of date browser. It may not display this or other websites correctly.You should upgrade or use an alternative browser. ShareGửi mail bằng thư viện PHPMailer
  • Thread starter Thread starter filiallion
  • Start date Start date 03/01/2018
  • Tags Tags mail oauth php phpmailer pop3 smtp
filiallion

filiallion

Administrator
Staff member Administrator Messages 590 Points 10 Language Tiếng Việt Đối với các bạn viết các ứng dụng web có gửi mail thì PHPMailer là một thư viện được chọn lựa. Mặc dù trong PHP đã có sẵn hàm gửi mail rồi nhưng thường thì hàm mail này bị chặn hoặc mail các bạn gửi có thể nằm trong mục spam. Việc sử dụng thư viện PHPMailer cũng khá đơn giản, các bạn theo dõi phần hướng dẫn sau đây để có thể sử dụng thư viện PHPMailer hiệu quả. Trước tiên, các bạn tải thư viện PHPMailer tại địa chỉ https://github.com/PHPMailer/PHPMailer. Trong gói thư viện này có 5 tập tin trong thư mục src, đây là toàn bộ thư viện PHPMailer mà các bạn cần sử dụng. Các bạn có thể sao chép 5 tập tin này vào ứng dụng web của các bạn. Tại vị trí các bạn muốn gửi mail, các bạn khai báo khối lệnh sau: PHP: //Require các thư viện PHPMailer require 'path/to/PHPMailer/Exception.php'; require 'path/to/PHPMailer/PHPMailer.php'; require 'path/to/PHPMailer/SMTP.php'; //Khai báo sử dụng namespace (Lưu ý tới vị trí khai báo này) use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; //Khởi tạo đối tượng PHPMailer $PHPMailer = new PHPMailer(true); //Khai báo cấu hình và gửi mail try { $PHPMailer->SMTPDebug = 2; $PHPMailer->isSMTP(); $PHPMailer->Host = 'smtp.example.com'; $PHPMailer->SMTPAuth = true; $PHPMailer->Username = '[email protected]'; $PHPMailer->Password = 'secret'; $PHPMailer->SMTPSecure = 'tls'; $PHPMailer->Port = 587; $PHPMailer->setFrom('[email protected]', 'From'); $PHPMailer->addAddress('[email protected]', 'Recipient'); $PHPMailer->isHTML(true); $PHPMailer->Subject = 'Here is the subject'; $PHPMailer->Body = 'This is the HTML message body'; $PHPMailer->send(); } catch (Exception $exception) { echo $PHPMailer->ErrorInfo; } Các bạn lưu ý thay đổi đường dẫn tới các tập tin thư viện cho chính xác cũng như các thông tin về máy chủ gửi mail, tài khoản, mật khẩu, cổng SMTP... Để CC hoặc BCC tới tài khoản khác, các bạn khai báo như sau: PHP: $PHPMailer->addCC('[email protected]'); $PHPMailer->addBCC('[email protected]'); Để đính kèm tập tin, các bạn khai báo như sau: PHP: $PHPMailer->addAttachment('path/to/file.zip'); Các bạn có thể tìm hiểu thêm về thư viện PHPMailer tại địa chỉ https://github.com/PHPMailer/PHPMailer/blob/master/README.md. You must log in or register to reply here. Share: Facebook X Bluesky LinkedIn Reddit Pinterest Tumblr WhatsApp Email Share Link
  • Home
  • Forums
  • Discussion
  • Web
  • PHP
Back Top

Từ khóa » Gửi Mail Bằng Thư Viện Phpmailer