Pages

Thursday, December 13, 2012

Setting Email di Xampp dengan akun GMail


-konfigurasi yang di ubah di php.ini :

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = test@gmail.com
sendmail_path = “\”D:\xampp\sendmail\sendmail.exe\” -t”

konfigurasi yang dirubah di sendmail.ini  (tambahkan script dibawah ini), lalu tambahkan marking # (di depan script ) untuk baris settingan yang selain dibawah ini:

# SMTP Gmail
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from test@gmail.com
auth on
user test@gmail.com
password 123456
port 587
account default : Gmail

- restart apache untuk apply changes settingan ini.

- testing email dengan attachment (copy paste script ini lalu jalankan) :

<?php

function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message)
{
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, “r”);
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = “From: “.$from_name.” <”.$from_mail.”>\r\n”;
$header .= “Reply-To: “.$replyto.”\r\n”;
$header .= “MIME-Version: 1.0\r\n”;
$header .= “Content-Type: multipart/mixed; boundary=\”".$uid.”\”\r\n\r\n”;
$header .= “This is a multi-part message in MIME format.\r\n”;
$header .= “–”.$uid.”\r\n”;
$header .= “Content-type:text/plain; charset=iso-8859-1\r\n”;
$header .= “Content-Transfer-Encoding: 7bit\r\n\r\n”;
$header .= $message.”\r\n\r\n”;
$header .= “–”.$uid.”\r\n”;
$header .= “Content-Type: application/octet-stream; name=\”".$filename.”\”\r\n”; // use different content types here
$header .= “Content-Transfer-Encoding: base64\r\n”;
$header .= “Content-Disposition: attachment; filename=\”".$filename.”\”\r\n\r\n”;
$header .= $content.”\r\n\r\n”;
$header .= “–”.$uid.”–”;
if (mail($mailto, $subject, “”, $header)) {
echo “email successfully send.”; // or use booleans here
BackupFile();
} else {
echo “email fail to send.!”;
}
}

$my_file = “JI.txt”;
$my_path = “D:\\xampp\\htdocs\\production_jst\\log_scan\\”;
$my_name = “IKP”;
$my_mail = “test@gmail.com”;
$my_replyto = “test@gmail.com”;
$my_subject = “Data production IKP to JI (“.date(‘Y-m-d H:i’).”)”;
$my_message = “Dear all,\r\n Please see attachment from IKP to JI.\r\n\r\nIKP.”;
$email_to = “adhikaraya@gmail.com”;
mail_attachment($my_file, $my_path, $email_to, $my_mail, $my_name, $my_replyto, $my_subject, $my_message);

?>

sumber  : http://www.galiannet.com/blog/?p=7

No comments:

Post a Comment