Php İletisim Formu
Bu dersimizde, Php ile iletişim formu nasıl yapılır bunu öğreneceğiz. Yapacağımız form ile Ziyaretçinin girdiği bilgiler e-mail adresimize gönderilecek.
İlk olarak ziyaretçinin bilgi gireceği index.php dosyasını oluşturalım
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < html xmlns = "http://www.w3.org/1999/xhtml" > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" /> < title >Iletisim Formu</ title > </ head > < body > < form name = "iletisim" method = "POST" action = "gonder.php" > Ad Soyad: < input type = "text" name = "ad_soyad" size = "25" >< br /> Telefon: < input type = "text" name = "tel" size = "25" >< br /> E-Mail: < input type = "text" name = "email" size = "25" >< br /> Mesajiniz: < textarea rows = "5" name = "mesaj" cols = "25" ></ textarea >< br /> < input type = "submit" name = "button" value = "Gonder" > </ form > </ body > </ html > |
Girilen bilgileri denetleyeceğimiz gonder.php dosyasını oluşturalım.
01
02
03
04
05
06
07
08
09
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
37
38
39
40
41
42
43
|
<?php $ad_soyad = $_POST [ "ad_soyad" ]; $tel = $_POST [ "tel" ]; $email = $_POST [ "email" ]; $mesaj = $_POST [ "mesaj" ]; $adres = "isim@siteadi.com" ; // Buraya e-postanin gonderilecegi mail adresini yaziniz $konu = "Iletisim Formu" ; $tarih = date ( 'Y-m-d' ); $ip_adresi = $_SERVER [ 'REMOTE_ADDR' ]; if (( $ad_soyad == "" ) or ( $tel == "" ) or ( $email == "" ) or ( $mesaj == "" )){ echo "<center>Lutfen Ad Soyad, Telefon, E-Mail ve Mesaj alanlarini bos birakmayiniz.<br><a href=index.php>Geri don</a></center>" ; } else { $mesajveri .= "ILETISIM FORMU MESAJI<br/><br/>" ; $mesajveri .= "E-Mail: " . $email . "<br/>" ; $mesajveri .= "Telefon: " . $tel . "<br/>" ; $mesajveri .= "Tarih: " . $tarih . "<br/>" ; $mesajveri .= "IP Adresi :" . $ip_adresi . "<br/>" ; $mesajveri .= "Mesaj: " . $mesaj ; $mesajyolla = mail( $adres , $konu , $mesajveri , "Content-type: text/html; charset=utf-8\r\n" ); if ( $mesajyolla ) { echo "<center>Iletisim mailiniz bize ulasti, en kisa surede cevaplanacaktir. Ilginiz icin tesekkur ederiz.<br><a href=index.php>Anasayfa</a></center>" ; } else { echo "<center>E-Mail gonderilirken hata olustu! Lutfen daha sonra tekrar deneyiniz.</center>" ; } } ?> |
gonder.php dosyasındaki mail@siteadresi.com adresini kendi mail adresiniz olarak değiştirin.
Gönderilen mailin içeriği şu şekilde:
İLETİŞİM FORMU MESAJI
E-Mail: admin@siteadresi.com
Telefon: 0555 555 55 55
Tarih: 2009-10-30
IP Adresi :91.44.77.29
Mesajı: Ziyaretçi mesajı