ข้ามไปที่เนื้อหาหลัก

การส่งอีเมล์ด้วย PHP โดยมีการเรียกใช้งาน Authen Account ของ Gmail

วิดีโอนี้เป็นการส่งอีเมล์ด้วย PHP โดยมีการเรียกใช้งาน Authen Account ของ Gmail ซึ่งจะมีวิธีแก้ปัญหา SMTP Error: Could not authenticate มาด้วยนะครับ




ตัวอย่างซอร์สโค้ดที่แก้ไขแล้ว
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?php
    include "pass.php";

    require_once('class.phpmailer.php');
    $mail = new PHPMailer();
    $mail->IsHTML(true);
    $mail->CharSet = "utf-8";
    $mail->IsSMTP();
    $mail->SMTPAuth = true; // enable SMTP authentication
    $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 465; // set the SMTP port for the GMAIL server
    $mail->Username = "youremail@gmail.com"; // GMAIL username
    $mail->Password = $password; // GMAIL password
    $mail->From = "youremail@gmail.com"; // "name@yourdomain.com";
    //$mail->AddReplyTo = "support@thaicreate.com"; // Reply
    $mail->FromName = "To be developer";  // set from Name
    $mail->Subject = "Test sending mail. ทดสอบการส่งอีเมล ครั้งที่ 2";
    $mail->Body = "My Body & <b>My Description ส่วนของรายละเอียดต่างๆ <font color='green'>ครั้งที่ 2</font></b>";

    $mail->AddAddress("friend@gmail.com", "Mr.Cyberman"); // to Address

    $mail->AddAttachment("thaicreate/myfile.zip");
    $mail->AddAttachment("thaicreate/myfile2.zip");

    //$mail->AddCC("member@thaicreate.com", "Mr.Member ShotDev"); //CC
    //$mail->AddBCC("member@thaicreate.com", "Mr.Member ShotDev"); //CC

    $mail->set('X-Priority', '1'); //Priority 1 = High, 3 = Normal, 5 = low

    if($mail->Send()){
        echo 'ส่งอีเมลเรียบร้อยแล้ว';
    }
?>
</body>
</html>

สนับสนุนค่ากาแฟผู้เขียนได้ที่

PHP CI MANIA PHP Code Generator 
โปรแกรมช่วยสร้างโค้ด ลดเวลาการเขียนโปรแกรม เขียนโปรแกรมง่ายและสะดวกขึ้น
สนใจสั่งซื้อราคาสุดคุ้ม >> http://fastcoding.phpcodemania.com/

ความคิดเห็น

ค้นหาในเว็บไซต์

เนื้อเพลงที่ได้รับความนิยม ในรอบสัปดาห์

ค้นหาบล็อกนี้