Gửi Mail Bằng Cách Sử Dụng SMTP Với PHPMailer - Code 24h

phpmailer-smtp-gmail-google-apps

PHPMailer là một lớp (class) PHP đơn giản cho việc gửi mail từ ứng dụng web của bạn, không giống như hàm chức năng mail() mặc định,

PHPMailer có những tính năng sau : – Dễ dàng cho việc gửi tập tin đính kèm – Dễ dàng sử dụng các class hướng đối tượng trong PHP – Hỗ trợ gửi HTML Email từ Scripts – Làm việc trên tất cả các nền Linux/BSD/Windows Và đây là cách sử dụng PHPMailer cho script của bạn :

require("phpmailer/class.phpmailer.php"); //**** //thay đổi các thông số này cho phù hợp với bạn $your_email = "[email protected] /* */ "; $your_smtp = "mail.example.com"; $your_smtp_user = "[email protected] /* */ "; $your_smtp_pass = "example_password"; $your_website = "http://example.com"; //**** //get contact form details $name = $_POST['name']; $email = $_POST['email']; $url = $_POST['url']; $comments = $_POST['comments']; $response="Name: $name Contents: $comments "; $mail = new PHPmailer(); $mail = $mail->SetLanguage("en", "phpmailer/language"); $mail->From = $your_email; $mail->FromName = $your_website; $mail->Host = $your_smtp; $mail->Mailer = "smtp"; $mail->Password = $your_smtp_pass; $mail->Username = $your_smtp_user; $mail->Subject = "$your_website feedback"; $mail->SMTPAuth = "true"; $mail->Body = $response; $mail->AddAddress($your_email,"$your_website admin"); $mail->AddReplyTo($email,$name); echo "<p>Thanks for your feedback, <em>$name</em>! We will contact you soon!</p>"; if (!$mail->Send()) { echo "<p>There was an error in sending mail, please try again at a later time</p>"; } $mail->ClearAddresses(); $mail->ClearAttachments();

Hy vọng với đoạn code này sẽ giúp cho việc gửi nhận email của các bạn sẽ dễ dàng và đơn giản hơn.Chúc các bạn thành công !

Tags: gửi mail hoc php lập trình php mail php code PHPMailer send mail

Chuyên Mục: PHP

Bài viết được đăng bởi webmaster

Từ khóa » Gửi Mail Bằng Phpmailer Class