SMTP -> DARI SERVER. 250-smtp. gmail. com siap melayani Anda, [119. 59. 120. 34] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
SMTP -> KESALAHAN. Kata sandi tidak diterima dari server. 535-5. 7. 8 Username dan Password tidak diterima. Pelajari lebih lanjut di 535 5. 7. 8 https. //dukung. google. com/mail/?p=BadCredentials p5-20020a170902bd0500b001932a9e4f2csm11204063pls. 255 - gsmtp
SMTP -> DARI SERVER. 250 2. 1. 5 Siram p5-20020a170902bd0500b001932a9e4f2csm11204063pls. 255 - gsmtp
Kesalahan SMTP. Tidak dapat mengautentikasi
PHPMailer adalah perpustakaan PHP yang memiliki fungsi bawaan untuk mengirim email dengan aman dan mudah menggunakan PHP dari server
Mail adalah fungsi yang berguna di situs web
Ini digunakan untuk verifikasi pengguna, lupa kata sandi, mengirim informasi, dll
Dalam tutorial ini, saya menunjukkan bagaimana Anda mengirim email menggunakan server SMTP dengan PHPmailer di PHP
[email protected]'; // SMTP username $mail->Password = 'password'; // SMTP password $mail->SMTPSecure = 'tls';//PHPMailer::ENCRYPTION_STARTTLS; Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted $mail->Port = 587; // TCP port to connect to
Tentukan id email dan nama pengirim di // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);4 dan id email penerima dan nama di // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);5
Tentukan subjek email, dan badan di // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);6, // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);7, dan // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);8
$mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Send email using SMTP with PHPmailer'; $mail->Body = 'A test email from <a href="//makitweb.com">maktiweb.com</a>'; $mail->AltBody = 'A test email from makitweb.com'; // Plain text for non-HTML mail clientsLampirkan file menggunakan metode // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);_9. Anda dapat menentukan nama file menggunakan parameter ke-2
$mail->addAttachment('upload/file.pdf'); $mail->addAttachment('upload/image.png', 'image 1'); // Optional nameHubungi $mail->SMTPDebug = 0; // 0 - Disable Debugging, 2 - Responses received from the server_0 untuk mengirim permintaan
Kode Selesai
<?php // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Load Composer's autoloader require 'vendor/autoload.php'; // Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 0; // 0 - Disable Debugging, 2 - Responses received from the server $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'mail.makitweb.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'password'; // SMTP password $mail->SMTPSecure = 'tls';//PHPMailer::ENCRYPTION_STARTTLS; Enable TLS encryption, `PHPMailer::ENCRYPTION_SMTPS` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('[email protected]', 'Yogesh singh'); $mail->addAddress('Recipient email-id', 'Recipient name'); // Add a recipient // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Send email using SMTP with PHPmailer'; $mail->Body = 'A test email from <a href="//makitweb.com">maktiweb.com</a>'; $mail->AltBody = 'A test email from makitweb.com'; // Plain text for non-HTML mail clients // Attachement $mail->addAttachment('upload/file.pdf'); $mail->addAttachment('upload/image.png', 'image 1'); // Optional name $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }4. Kesimpulan
Dapatkan detail SMTP dari cPanel jika Anda tidak memilikinya dan gunakan untuk mengonfigurasi PHPMailer. Aktifkan debugging dengan menetapkan 2 ke <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Load Composer's autoloader require 'vendor/autoload.php';6 jika mendapatkan masalah saat mengirim email