Pada kesempatan kali ini, saya akan berbagi ilmu mengenai Pembuatan Email Gateway dengan SMTP Gmail.
Langkah-langkah nya :
- Download source code PHP Mailer di sini
- Unzip/Extract foldernya ke root atau direktori web anda
- Buat file index.php
- Copas (di copy trus paste ke file index.php) source code dibawah dan ganti text berwarna merah sesuai data anda.
$mail = new PHPMailer();
//$mail->IsSMTP(); // telling the class to use SMTP
// $mail->Host = "localhost"; // SMTP server
//IsSMTP(); // send via SMTP
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server Gmail
$mail->Mailer = "smtp";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “username@gmail.com”; //
$mail->Password = “password”; // SMTP password
$webmaster_email = “username@domain.com”; //Reply to this email ID
$email=”username@domain.com”; // Recipients email ID
$name=”name”; // Recipient’s name
$mail->From = $webmaster_email;
$mail->FromName = “Webmaster”;
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,”Webmaster”);
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment(“/var/tmp/file.tar.gz”); // attachment
$mail->AddAttachment(“/tmp/image.jpg”, “new.jpg”); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = “This is the subject”;
$mail->Body = “Hi,This is the HTML BODY “; //HTML Body
$mail->AltBody = “This is the body when user views in plain text format”; //Text Body
if(!$mail->Send())
{
echo “Mailer Error: ” . $mail->ErrorInfo;
}
else
{
echo “Message has been sent”;
}
?> - Edit file php.ini di folder C:\Xampp\php atau C:\xampp\apache\bin
smtp_port = 587
sendmail_from = emailanda@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\" -t"
6. Edit file sendmail.ini di folder C:\Xampp\sendmail
Untuk Xampp versi lama :
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from emailanda@gmail.com
auth on
user emailanda@gmail.com
password passwordanda
port 587
account default : Gmail
dan Xampp versi baru :
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
default_domain=gmail.com
auth_username=emailanda@gmail.com
auth_password=passwordanda
Pastikan port dan settingan nya benar,
Kasus yang saya alami, setelah semua error bisa diatasi, ternyata gangguan utama nya adalah Proxy.
Jadi email gateway tidak mau berjalan pada jaringan kantor yang ada Proxy nya.
Selamat Mencoba :)