Hiển thị các bài đăng có nhãn Send Email SMTP. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Send Email SMTP. Hiển thị tất cả bài đăng

Thứ Ba, 14 tháng 4, 2026

SEND EMAIL SMTP - KEIEIJUKU - send supplier

 require_once 'classes/class.phpmailer.php';

require_once 'classes/class.smtp.php';

<!-- take include/data/mail_config.php 

$SuppEmail = email_mail

$mailHost

$mailUsername

$mailPassword

$mailsetFrom 

-->

===== MAIL GỬI CHO SUPPLIER =====

$mail = new PHPMailer();

$mail->CharSet = 'UTF-8';

$mail->isSMTP();


$mail->SMTPKeepAlive = true;

$mail->SMTPDebug = 0;

// $mail->Timeout = 10;

$mail->Host       = $mailHost;

$mail->SMTPAuth   = true;

$mail->Username   = $mailUsername;

$mail->Password   = $mailPassword;

$mail->SMTPSecure = 'ssl';

$mail->Port       = 465;


$mail->setFrom($mailsetFrom, 'KEIEIJUKU KBN');

$mail->addAddress($supplier);

$mail->addReplyTo($customer);

$mail->isHTML(true);

$mail->Subject = $subject;

$mail->Body    = $body;

// ===== MAIL GỬI CHO KHÁCH (NGAY LẬP TỨC) =====

$mail2 = new PHPMailer();

$mail2->CharSet = 'UTF-8';

$mail2->isSMTP();

$mail2->SMTPKeepAlive = true;

$mail2->SMTPDebug = 0;

// $mail2->Timeout = 3;


$mail2->Host       = $mailHost;

$mail2->SMTPAuth   = true;

$mail2->Username   = $mailUsername;

$mail2->Password   = $mailPassword;

$mail2->SMTPSecure = 'ssl';

$mail2->Port       = 465;


$mail2->setFrom($mailsetFrom, 'KEIEIJUKU KBN');

$mail2->addAddress($customer);


$mail2->isHTML(true);

$mail2->Subject = 'Xác nhận đã gửi yêu cầu từ website KEIEIJUKU KBN';

$mail2->Body    = $body;

## Send-Mail

$start = microtime(true);

// gửi mail supplier trước

$ok1 = $mail->send();

$time1 = microtime(true);

// chỉ gửi mail khách nếu mail 1 OK

$ok2 = false;

if($ok1){

    $ok2 = $mail2->send();

}

$time2 = microtime(true);

## ------------------------- ##

// tính thời gian

$time_supplier = round($time1 - $start, 3);

$time_customer = round($time2 - $time1, 3);

$total_time    = round($time2 - $start, 3);

// ghi log

file_put_contents('debug_time.txt',

    "Supplier: {$time_supplier}s\n" .

    "Customer: {$time_customer}s\n" .

    "Total: {$total_time}s\n\n",

    FILE_APPEND

);

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>