Cara Kirim Email melalui PHP



Ada dua file yang harus diubah settingan defaultnya jika ingin melakukan pengiriman email melalui PHP.

1. file php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = smtp.gmail.com
; http://php.net/smtp-port
;smtp_port = 465
 
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = reboot.bs@gmail.com
 
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"\xampp\sendmail\sendmail.exe\" -t"

2. file sendmail.ini
# Example for a user configuration file
 
# Set default values for all following accounts.
defaults
logfile "\xampp\sendmail\sendmail.log"
 
# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off
 
# A freemail service example
#account Gmail
#tls on
#port 465
#tls_certcheck off
#host smtp.gmail.com
#from andika@gmail.com
#auth on
#user andika@gmail.com
#password 1234
 
# Set a default account
#account default : Gmail
 
#=======Tambahkan Koding dibawah ini ya =============
# SMTP Gmail
account Gmail
tls on
port 465
tls_starttls off
tls_certcheck off
host smtp.gmail.com
from andika@gmail.com
auth on
user andika@gmail.com
password #####
 
account default : Gmail


3. Test pengiriman email Silahkan buat file test pengiriman email dengan PHP, berikut contoh nya,
<?php
 
$tujuan = "andika@gmail.com";
$subject = "Contoh Email";
$pesan = "Ini hanya contoh email saja";
if(mail($tujuan, $subject, $pesan)){
 echo"Terkirim BRO..";
}else{
 echo"Gagal BRO";
}
?>



Source : ributbudisantoso.blogspot.com

0 komentar:

Post a Comment