Cara Konfigurasi SMTP mail authentication dengan PHPMailer

Fungsi mail() di php sering dimanfaatkan spammer untuk mengirimkan email tanpa sepengetahuan pemilik websites yang menggunakan celah keamanan wordpess. Penambahan plugins SMTP mail athentication dapat menghindari penggunaan fungsi mail(), selanjutnya fungsi mail() dapat dinonaktipkan dari file php.ini dengan menambahkan kode disable_functions = mail dan pengaktipan untuk seluruh folder melalui .htaccess, atau dinonaktipkan secara global di server.

Plugins ini tidak akan berguna bila websites anda  tidak ditambahkan anti-spam, silahkan tambahkan anti-spam terlebih dahulu.
Dalam artikel ini  email dianggap sudah ada dengan user dan password yang benar, bila belum ada silahkan didaftarkan mengikuti artikel berikut.



  1. Download PHPMailer di http://phpmailer.worxware.com

  2. ekstract ke websites misalnya ke folder phpmailer

  3. buka script php yang mengirimkan email dan modifikasi.

  4. tambahkan kode: require_once('phpmailer/class.phpmailer.php');

  5. Pastikan lokasi foldernya benar dengan menyesuaikan folder yang dibuat.

  6. Sesuaikan form anda dengan kode dibawah misalnya subject, body, mailform, dll.

contoh modifikasi:


require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();

$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 587; // set the SMTP port
$mail->Username = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}


contoh Konfigurasi gmail:

SMTP Host: smtp.gmail.com
SMTP Port: 465
Username : alamat email lengkap contoh username@gmail.com
Password : password email



contoh Konfigurasi mail yahoo:

SMTP Host: smtp.mail.yahoo.com
SMTP Port: 465
Username : alamat email lengkap contoh username@yahoo.com
Password : password email



contoh Konfigurasi outlook.com:

SMTP Host: smtp-mail.outlook.com
SMTP Port: 587
Username : alamat email lengkap contoh username@outlook.com
Password : password email

Comments

Popular posts from this blog

Error The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 93D6889F9F0E78D5

cara mengembalikan account facebook yang dibajak/dihack

Membangun Jaringan VLAN sederhana di Mikrotik dengan menggunakan wifi internal mikrotik dan tanpa menggunakan switch mikrotik.