Mengirim e-mail lewat server SMTP Gmail dengan PHP

Gimana ya caranya kalo kita ingin memangil fungsi mail() tapi alamat server SMTP  kita adalah Gmail??

Misalnya karena dengan berbagai alasan kita nggak mau pake fungsi mail dai web kita maka kita gunakan Gmail…

Jadi disini kita ibaratkan Gmail itu sebagai “tukang pos”…

(maaf.. bukannya mau merendahkan Gmail.. heehehe).

nah..

Berikut ini adalah sedikit ilmu yang saya ambil dari beberapa referensi :

1.  Cara yang pertama adalah kita download Fake Mail disini atau disini

2. Kemudian kita unpack sendmail.php ke c:\xampp\

3. Buka file sendmail.ini, kemudian cari entry smpt_server ,  smtp_port , auth_username, dan auth_password.

ini contoh konfigurasinya :

[sendmail]

; you must change mail.mydomain.com to your smtp server,

; or to IIS’s “pickup” directory. (generally C:\Inetpub\mailroot\Pickup)

; emails delivered via IIS’s pickup directory cause sendmail to

; run quicker, but you won’t get error messages back to the calling

; application.

smtp_server=smtp.gmail.com

; smtp port (normally 25)

smtp_port=587

; the default domain for this server will be read from the registry

; this will be appended to email addresses when one isn’t provided

; if you want to override the value in the registry, uncomment and modify

;default_domain=mydomain.com

; log smtp errors to error.log (defaults to same directory as sendmail.exe)

; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)

; uncomment to enable debugging

;debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username=youremail@gmail.com

auth_password=password

4. Selain entry yang sudah disebutkan diatas, kasih tanda “;” untuk menonaktifkan…

5. Kemudian ubah konfigurasi PHP (php.ini) pada bagian [mail function] pada baris sendmail_path. Isi nilai sendmail_path dengan C:\xampp\sendmail\sendmail.exe -t pada sendmail_path. Kalau ada tanda “;”, hapus aja untuk mengaktifkan line tersebut. Contohnya konfigurasinya sebagai berikut.

[mail function]

; For Win32 only.

;SMTP = localhost

;smtp_port = 25

; For Win32 only.

;sendmail_from = webmaster@localhost

; For Unix only. You may supply arguments as well (default: “sendmail -t -i”).

sendmail_path = “C:\sendmail\sendmail.exe -t”

; Force the addition of the specified parameters to be passed as extra parameters

; to the sendmail binary. These parameters will always replace the value of

; the 5th parameter to mail(), even in safe mode.

;mail.force_extra_parameters =

6. Kemudian restart xampp

7. Untuk mencoba, gunakan script sederhana dibawah ini :

<?php

/**

* @author MAS2EKONDANG

* @copyright 2009

*/

//Nama Pengirim

$from_name = “PC Lokal”;

//letakkan alamat email pengirim (boleh diisi apa aja)

$from_email = “admin@localhost.com”;

$headers = “From: $from_name <$from_email>”;

$body = “Hi, \ntest kirim email dari $from_name <$from_email>.”;

$subject = “Test email dari PC Lokal”;

//letakkan alamat emait tujuan (penerima)

$to = “email_tujuan@mail.com”;

if (mail ($to, $subject, $body, $headers)) {

echo “berhasil!”;

} else {

echo “gagal…”;

}

?>

Selamat mencoba..

mudah2an lancar.. :D

Advertisement

One Response to Mengirim e-mail lewat server SMTP Gmail dengan PHP

  1. mas2ekondhang says:

    koneksi internetnya mungkin mas..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.