Saya mencoba mengirim email dengan memanfaatkan class/Helper Email di Codeigniter, selalu masuk spam. Akhirnya menemukan cara yang native dan aman untuk mengirim email memalui programming PHP/CI.
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
Buka browser, ijinkan less secure dan unlock
https://www.google.com/settings/security/lesssecureapps
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Contoh Kode :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | require_once "Mail.php"; include_once('Mail/mime.php'); $from=''; $pass=''; $to =''; $subject=''; $text=''; $crlf = "\n"; $headers = array( 'From' => $from, 'To' => $to, 'Subject' => $subject ); $mime = new Mail_mime(array('eol' => $crlf)); $mime->setHTMLBody($text); $body = $mime->get(); $hdrs = $mime->headers($headers); $smtp = Mail::factory('smtp', array( 'host' => 'ssl://smtp.gmail.com', 'port' => '465', 'auth' => true, 'username' => $from, 'password' => $pass )); $mail = $smtp->send($to, $hdrs, $body); if (PEAR::isError($mail)) { echo('<p>' . $mail->getMessage() . '</p>'); } else { return 1; } |