Mau aplikasi PHP kamu bisa mengirim email walaupun kamu menjalankannya di localhost dengan OS Windows? Mau tau caranya? silahkan teruskan membacanya :D .

Untuk mengirim email menggunakan fungsi mail dari localhost yang perlu dilakukan adalah mengubah konfigurasi PHP (file php.ini) pada bagian [mail function] seperti 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 = 
 
; 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 =

Syarat untuk melakukan perubahan ini adalah kamu harus punya smtp server. Bagaimana jika tidak punya? Jika kamu punya website, kamu bisa menggunakan smtp server website kamu, misalnya mail.domain-anda.tld. Pada bagian SMTP ganti nilai localhost dengan mail server kamu, misalnya mail.domain-anda.tld, sedangkan pada bagian smtp_port ganti dengan port smtp server kamu, standarnya 25. Jangan lupa uncomment kedua baris tersebut dengan menghapus tanda titik koma (;) sehingga setingannya akan seperti berikut.

[mail function]
; For Win32 only.
SMTP = mail.domain-anda.tld
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 = 
 
; 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 =

Simpan dan restart apache kamu dan selamat mencoba. Saya sendiri sudah mencobanya dan berhasil.

Cara yang lain yang bisa digunakan untuk mengirim email menggunakan php mail dari windows adalah dengan menggunakan fake sendmail yang dibuat oleh Byron Jones. Fake sendmail mirip dengan sendmail pada linux. Pertama unduh fake sendmail untuk windows di sini atau di sini, kemudian ekstrak. Lalu buka file sendmail.ini dengan text editor, kemudian cari baris smtp_server, smtp_port. Ganti nilai smtp_server, smtp_port dengan smtp server dan smtp port website kamu. Contohnya seperti berikut.

[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=mail.domain-anda.tld
 
; smtp port (normally 25)
 
smtp_port=25

Kemudian ubah konfigurasi PHP (php.ini) pada bagian [mail function] pada baris sendmail_path. Isi nilai sendmail_path dengan “path\to\sendmail.ext -t”. Misalkan kamu menyimpan file sendmail.exe pada folder C:\sendmail\sendmail.exe maka isikan “C:\sendmail\sendmail.exe -t” pada sendmail_path. Contohnya 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 =

Kemudian restart apache dan siap untuk dicoba.

Dengan menggunakan fake sendmail kamu bisa menggunakan smtp server nya google asalkan kamu punya account google mail (gmail). Caranya ubah nilai smpt_server menjadi smtp.gmail.com, smtp_port menjadi 587 dan juga pada baris auth_username dan auth_password isi dengan email dan password gmail kamu. Contoh konfigurasinya seperti berikut.

[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

Selamat mencoba, jika berhasil selamat ya, jika gagal mungkin ada yang salah dengan konfigurasinya atau kamu belum terhubung dengan internet, silahkan diperiksa dan dicoba lagi :D

28 Comments to “Mengirim email menggunakan php mail dari localhost”

  • Ou.. gebono toh mas caranya. :D
    thx u ilmu nya mas..
    :D

Post comment