Thứ Năm, 26 tháng 2, 2026

Send Email Server SMTP

Demo MadeChina 
1️⃣ Tải bản 5.2.27

Link tải trực tiếp:
https://github.com/PHPMailer/PHPMailer/archive/refs/tags/v5.2.27.zip

Upload 2 file:

class.phpmailer.php
class.smtp.php

Ghi đè lên bản cũ.

tải file: tại đây

----------------------------------------****-----------------------------------------

Code Run

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once 'classes/class.phpmailer.php';
require_once 'classes/class.smtp.php';

if(isset($_POST['send'])){

    $nguoigui = trim($_POST['nguoigui']);
    $content  = trim($_POST['content']);

    if(empty($nguoigui) || empty($content)){
        echo "<p style='color:red'>Thiếu dữ liệu</p>";
    }else{

        require_once 'includes/data/mail_config.php';

        $mailnhan     = $mail_email;
        $mailHost     = $mail_mailserver;
        $mailUsername = $mail_username;
        $mailPassword = $mail_password;
        $mailsetFrom  = $mail_username;

        $mail = new PHPMailer();
        $mail->CharSet = 'UTF-8';
        $mail->isSMTP();        

        /* ===== BẬT DEBUG ===== */
        // show error + note Email 
        $mail->SMTPDebug = 2;
        $mail->Debugoutput = 'html';


        $mail->Host       = $mailHost;
        $mail->SMTPAuth   = true;
        $mail->Username   = $mailUsername;
        $mail->Password   = $mailPassword;
        $mail->SMTPSecure = 'ssl';   
        $mail->Port       = 465;
        // Change 'SMTPSecure = tls' **** 'Port = 587' 
        // Not Support version < php 5..


        $mail->setFrom($mailsetFrom, 'KEIEIJUKU KBC');
        $mail->addAddress($mailnhan);
        $mail->addReplyTo($nguoigui);

        $mail->isHTML(true);
        $mail->Subject = "Test gửi mail";
        $mail->Body    = "<h3>Email từ: ".$nguoigui."</h3><p>".$content."</p>";

        if($mail->send()){
            echo "<h3 style='color:green'>Send Success</h3>";
        }else{
            echo "<h3 style='color:red'>Send Fail</h3>";
            echo "<strong>Error:</strong> ".$mail->ErrorInfo;
        }
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test gửi mail</title>
</head>
<body>

<h2>Form gửi mail test</h2>

<?php
// kiểm tra server SMTP
$fp = fsockopen("mail93155.maychuemail.com", 465, $errno, $errstr, 10);
if (!$fp) {
    echo "Lỗi: $errstr ($errno)";
} else {
    echo "Kết nối OK";
    fclose($fp);
}

?>

<form method="post">
    <label>Email người gửi:</label><br>
    <input type="email" name="nguoigui" required><br><br>

    <label>Nội dung:</label><br>
    <textarea name="content" rows="5" required></textarea><br><br>

    <button type="submit" name="send">Gửi mail</button>
</form>

</body>
</html>

Không có nhận xét nào:

Đăng nhận xét