PHP Programming
PHPMailer untuk Pengiriman Email Menggunakan CPanel

PHPMailer untuk Pengiriman Email Menggunakan CPanel

Oleh | Jum'at, 14 Juli 2023 00:31 WIB | 562 Views | Comments 2023-07-14 00:31:45

Tidak sedikit yang memanfaatkan email internal atau email yang dibawa oleh Cpanel untuk mengirimkan transactional email seperti informasi lupa password dan pengiriman email lainnya. Tapi sering gagal dan salah konfigurasi, lalu bagaimana konfigurasi yang benar?

Terlebih dahulu kita lihat setingan default dari cpanel, biasanya seperti ini
Email Cpanel
Nah, jika setingannya default seperti diatas, maka konfigurasi PHPMailernya dapat dilakukan seperti dibawah ini:
 

<?php
<?php
//Load vendor/lokasi phpmailer terlebih dahulu

$mail = new PHPMailer(true);

try {
 //Server settings
 $mail->SMTPDebug = 2; // aktifkan debug bila dibutuhkan
 $mail->isSMTP(); // Set mailer to use SMTP
 $mail->Host = 'mail.domain.com'; // Specify main and backup SMTP servers
 $mail->SMTPAuth = true; // Enable SMTP authentication
 $mail->Username = 'user@domain.com'; // SMTP username
 $mail->Password = 'secret'; // SMTP password
 $mail->SMTPSecure = 'tls'; // setingan ini yang biasanya terlewat
 $mail->Port = 587; // TCP port to connect to

//Recipients
 $mail->setFrom('from@example.com', 'Mailer');
 $mail->addAddress('recipient1@example.net', 'Joe User'); // Add a recipient
 $mail->addAddress('recipient2@example.com'); // Name is optional
 $mail->addReplyTo('info@example.com', 'Information');
 $mail->addCC('cc@example.com');
 $mail->addBCC('bcc@example.com');

// Content
 $mail->isHTML(true); // Set email format to HTML
 $mail->Subject = 'Here is the subject';
 $mail->Body = 'This is the HTML message body <b>in bold!</b>';
 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
 echo 'Message has been sent';

} catch (Exception $e) {
 echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Selamat mencoba


Baca atau Download PDF Adi Sumaryadi - Bicara IT dan Internet







Mungkin anda tertarik menonton video tentang Produk atau Services? - Belajar Bisnis Digital 3


PHP Programming Lainnya