Hướng dẫn phpmailer receive email - phpmailer nhận email

Do hàm mail() của PHP bị khóa vì lý do bảo mật, nếu mã nguồn PHP của bạn gặp phải vấn đề sử dụng hàm này, bạn nên chuyển sang dùng PHPMailer để hoạt động được và không lệ thuộc hàm mail() nữa.mail() của PHP bị khóa vì lý do bảo mật, nếu mã nguồn PHP của bạn gặp phải vấn đề sử dụng hàm này, bạn nên chuyển sang dùng PHPMailer để hoạt động được và không lệ thuộc hàm mail() nữa.

Khi gởi email bằng PHPMailer, bạn sẽ gởi email có địa chỉ người gởi là một địa chỉ có thực và là địa chỉ của bạn. Nếu bạn chưa có tài khoản email dành cho việc này, bạn cần vào Control Panel để tạo một hộp thư. Trong ví dụ này, bạn sẽ dùng địa chỉ là và mật khẩu là password.

Download mã nguồn PHPMailer

Đầu tiên, bạn cần tải mã nguồn PHPMailer tại địa chỉ: https://github.com/Synchro/PHPMailer (nhấn vào nút ZIP).

Sau khi tải về, bạn giải nén vào thư mục public_html. Bạn sẽ nhìn thấy thư mục này có dạng: public_html/PHPMailer_5.2.0. Tiếp theo, bạn điều chỉnh mã nguồn website để sử dụng.

Tạo một Form để nhập nội dung Email

Bạn tạo một trang đặt tên là email.php với nội dung như bên dưới:

Email:
Email:

Message:


Bổ sung PHPMailer vào mã nguồn

// $email and $message are the data that is being// posted to this page from our html contact form$email = $_REQUEST[’email’] ;$message = $_REQUEST[‘message’] ;
// posted to this page from our html contact form
$email = $_REQUEST[’email’] ;
$message = $_REQUEST[‘message’] ;

// When we unzipped PHPMailer, it unzipped to// public_html/PHPMailer_5.2.0require(“PHPMailer_5.2.0/class.PHPMailer.php”);
// public_html/PHPMailer_5.2.0
require(“PHPMailer_5.2.0/class.PHPMailer.php”);

$mail = new PHPMailer();

// set mailer to use SMTP$mail->IsSMTP();
$mail->IsSMTP();

// As this email.php script lives on the same server as our email server// we are setting the HOST to localhost$mail->Host = “localhost”;  // specify main and backup server
// we are setting the HOST to localhost
$mail->Host = “localhost”;  // specify main and backup server

$mail->SMTPAuth = true;     // turn on SMTP authentication

// When sending email using PHPMailer, you need to send from a valid email address// In this case, we setup a test email account with the following credentials:// email: // pass: password$mail->Username = “”;  // SMTP username$mail->Password = “password”; // SMTP password
// In this case, we setup a test email account with the following credentials:
// email:
// pass: password
$mail->Username = “”;  // SMTP username
$mail->Password = “password”; // SMTP password

// $email is the user’s email address the specified// on our contact us page. We set this variable at// the top of this page with:// $email = $_REQUEST[’email’] ;$mail->From = $email;
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST[’email’] ;
$mail->From = $email;

// below we want to set the email address we will be sending our email to.$mail->AddAddress(“”, “Brad Markle”);
$mail->AddAddress(“”, “Brad Markle”);

// set word wrap to 50 characters$mail->WordWrap = 50;// set email format to HTML$mail->IsHTML(true);
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = “You have received feedback from your website!”;

// $message is the user’s message they typed in// on our contact us page. We set this variable at// the top of this page with:// $message = $_REQUEST[‘message’] ;$mail->Body    = $message;$mail->AltBody = $message;
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST[‘message’] ;
$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->Send()){echo “Message could not be sent. ”;echo “Mailer Error: ” . $mail->ErrorInfo;exit;}
{
echo “Message could not be sent.

”;
echo “Mailer Error: ” . $mail->ErrorInfo;
exit;
}

echo “Message has been sent”;?>
?>

Lưu ý cuối cùng: Đa số Cloud Hosting và Email Server không cho phép bạn gởi email có địa chỉ người gởi (FROM) khác với tên miền bạn đang dùng. Ví dụ nếu bạn đã tạo account dùng để gởi email là nhưng lại để địa chỉ FROM là là không hợp lệ. Máy chủ sẽ từ chối và báo lỗi.

Nguồn: Using phpMailer to Send Mail through PHP – by Brad Markle

Hướng dẫn phpmailer receive email - phpmailer nhận email

Gửi ph

Do ha mail () Tham Khảo: Trang web Php gặp lỗi Khia Dùng Hàm Mail () Để GởI Email.mail() của PHP bị khóa vì lý do bảo mật, nếu mã nguồn PHP của bạn gặp phải vấn đề sử dụng hàm này, bạn nên chuyển sang dùng PHPMailer để hoạt động được và không lệ thuộc hàm mail() nữa. Tham khảo: Website PHP gặp lỗi khi dùng hàm mail() để gởi Email.

Khi gởi Email bằng Phpmailer, bạn sẽ gởi email Có Đị Nếu bạn chưa đó là tài Khoản email dàoo cho việc nào, bạn cần vào điều khiển điều khiển Để tạo một hộp thư. Trong ví dụ này, bạn sẽ dùng Địa chỉ là và mật khẩu là passw0rd. và mật khẩu là passw0rd.

Tải xuống MÃ NGUồN PHPMailer

Đầu tiên, bạn cần tải mà nguồn phpmailer tại địa chỉ: https://github.com/phpmailer/phpmailer (NHấn Vào

Sau Khiếu Bạn Sẽ NHìN thấy thư Mục nào ngắn dạng: public_html/PHPMailer_5.2.0. Tiếp Theo, bạn Điều chỉnh mà nguồn Trang web Để Sử Dụng.

TạO MộT Mẫu Đội

Bạn tạo một trang Đặt Tênn là ________ 9với nội phân NHư Bênn dưới:email.phpvới nội dung như bên dưới:

& nbsp;

____10password1 password2password3password4 password5password3password7password8

password9public_html0public_html1 public_html2password3public_html4

password9public_html/PHPMailer_5.2.03

password9password0public_html/PHPMailer_5.2.06 public_html2password3__

password9password0public_html1 public_html8password37

passw0rd2password1password8

Bổ Sung phpmailer vào mà nguồn

& nbsp;

passw0rd5

____10password1 password2password3password4 password5password3password7password8

password9public_html0public_html1 public_html2password3public_html4

public_html8public_html9public_html/PHPMailer_5.2.00public_html/PHPMailer_5.2.01

password9password0public_html/PHPMailer_5.2.06 public_html2password3__

public_html/PHPMailer_5.2.02public_html/PHPMailer_5.2.07

public_html/PHPMailer_5.2.02public_html/PHPMailer_5.2.09email.php0email.php1

public_html/PHPMailer_5.2.02email.php3

public_html/PHPMailer_5.2.02email.php5email.php6email.php1

public_html/PHPMailer_5.2.02email.php9password00password01

public_html/PHPMailer_5.2.02password03passw0rd6password05

public_html/PHPMailer_5.2.02password07email.php6password09password10public_html/PHPMailer_5.2.01

public_html/PHPMailer_5.2.02password13

public_html/PHPMailer_5.2.02password15

public_html/PHPMailer_5.2.02password17password18password05

public_html/PHPMailer_5.2.02password21public_html2password05

public_html/PHPMailer_5.2.02password25public_html2password05

password28password29public_html/PHPMailer_5.2.02password31

password32

password33password34 password35password05

password33password34 password39 password40public_html/PHPMailer_5.2.022

password33password44password05

password46

password34 password48password05

password50

Phpmailer gởi mail smtp bằng gmail/Ứng dụng Google

Quý Khách tạo 1 filen send.php với nội phân

include "class.phpmailer.php";
include "class.smtp.php";

& nbsp; $ mail = mới phpmailer (); $ mail-> issmtp (); // Đặt Mailer để sử dụng smtp $ mail-> host = "smtp.gmail.com"; // chỉ định máy chủ chính và sao lưu $ mail-> port = 465; // Đặt cổng để sử dụng $ mail-> smtpauth = true; // Bật xác thực SMTP $ mail-> smtpsecure = 'ssl'; $ mail-> username = ""; // Tên người dùng SMTP của bạn hoặc tên người dùng gmail của bạn $ mail-> password = "passwordhere"; // Mật khẩu SMTP của bạn hoặc mật khẩu gmail của bạn $ từ = ""; // Trả lời email này $ to = ""; // người nhận email id $ name = "ky thuat pa"; // Tên của người nhận $ mail-> từ = $ từ; $ mail-> fromName = "của bạn từ tên"; // Tên để cho biết email đến từ đâu khi nhận được $ ; // Đặt Word Wrap $ mail-> ishtml (true); . // cơ thể html $ mail-> altbody = "mail nay duoc gui bang smtp gmail phân phpmailer. - www.pavietnam.vn"; // cơ thể văn bản // $ mail-> smtpdebug = 2; if (! $ Mail-> send ()) {& nbsp; & nbsp; & nbsp; Echo "Loi Khim Goi Mail:". $ mail-> errorinfo. '';} khác {& nbsp; & nbsp; & nbsp; echo "Gửi thư Thanh Cong";}?>
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'ssl';
$mail->Username = ""; // your SMTP username or your gmail username
$mail->Password = "passwordhere"; // your SMTP password or your gmail password
$from = ""; // Reply to this email
$to=""; // Recipients email ID
$name="Ky Thuat PA"; // Recipient's name
$mail->From = $from;
$mail->FromName = "Your From Name"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress($to,$name);
$mail->AddReplyTo($from,"Ky Thuat PA");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Gui mail script from www.pavietnam.vn";
$mail->Body = "Mail nay duoc gui bang SMTP Gmail dung phpmailer class. - www.pavietnam.vn"; //HTML Body
$mail->AltBody = "Mail nay duoc gui bang SMTP Gmail dung phpmailer class. - www.pavietnam.vn"; //Text Body
//$mail->SMTPDebug = 2;
if(!$mail->Send())
{
    echo "

Loi khi goi mail: " . $mail->ErrorInfo . '

';
}
else
{
    echo "

Send mail thanh cong

";
}
?>

Để GửI TÀi Khoản Mở rộng php_openssl cầi được cài đặt -& nbsp; & nbsp; & nbsp; Gmail sử dụng smtpsecure (SSL) Để GửI Email -& nbsp; & nbsp; & nbsp; Khim sử dụng ssl của gmail Chún
-    Extension php_openssl cầi được cài đặt
-    Gmail sử dụng SMTPSecure (ssl) để gửi email
-    Khi sử dụng ssl của gmail chúng ta phải sử dụng port 465


Lưu Ý Cuối Cùng: ĐA Số Web Hosting Và Email Server Không Cho Phéph BạN GởI email Có Đị Ví dụ nếu Máiy chủ sẽ từ chối và báio lỗi. Đa số Web Hosting và Email Server không cho phép bạn gởi email có địa chỉ người gởi (FROM) khác với tên miền bạn đang dùng. Ví dụ nếu bạn đã tạo account dùng để gởi email là nhưng lại để địa chỉ FROM là là không hợp lệ. Máy chủ sẽ từ chối và báo lỗi.