BTC USD 81,115.0 Gold USD 4,378.12
Time now: Jun 1, 12:00 AM

camne nak buat contact us php

sanz

Super Active Member
Messages
5,913
Joined
Jul 30, 2008
Messages
5,913
Reaction score
486
Points
81
sape2 leh ajar ke? nak buat contact us tu. kat website kite, user bole hantar email kpd kite melalui form.
 
aku leh ajarkan...
step 1:
buatkan database untuk form ko:
contohnye name database ko 'form' n name table ko 'contactus'
buat row untuk 'name' 'email' 'contact' and message
or ko just guna syntax sql aku nie:
CREATE TABLE `contactus` (
`num` INT( 10 ) NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 30 ) NOT NULL ,
`email` VARCHAR( 30 ) NOT NULL ,
`contact` VARCHAR( 30 ) NOT NULL ,
`message` VARCHAR( 60 ) NOT NULL
) ENGINE = MYISAM ;

copy paste kt syntax sql n run..

step 2:
buatkan form:
kalau nak ikut script aku leh gak :
ko tengok kt action tue, tu yang akan process kopnye form.
<form method="POST" action="process.php">

<fieldset style="padding: 2">
<legend>Contact us</legend>
Name    :<input type="text" name="name" id="name" size="41"><p>Email    :<input type="text" name="email" id="email" size="41"></p>
<p>Contact No:<input type="text" name="contact" id="contact" size="41"></p>
<p>Message    :</p>
<p><textarea rows="8" name="massage" id="message" cols="46"></textarea></p>
<p> </p>
</fieldset><p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

save kan sebagai 'form.php'
copy je script tu.. paste kat php editor atau ko leh guna note pad save as form.php

step 3:
ko buatkan script processor untuk form ko script tu camnie:
<?
$db_hostname = "localhost"; //kebiasaannya "localhost"
$db_username = "root"; //user name ko
$db_pass = ""; //kalau ade password letak je password
$db_name = "form"; //name database

$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


$sql="INSERT INTO contactus (name,email,contact,message) VALUES
('$_POST[name]','$_POST','$_POST[contact]','$_POST[message]')";

$result=mysql_query($sql);
if($result){
header("location:berjayadihantar.php");
}
else
die('Error: ' .mysql_error());
?>

save as process.php macam kat action method di form td

step 4:
buat kan page untuk form yang berjaya:

copy kan script nie:
<!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>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
color: #BBBBBB;
font-size: 9px;
}
-->
</style>
</head>

<body>
<div align="center">
<p>Berjaya Dihantar</p>
<p> </p>
<p class="style1">tutorial by:</p>
<p class="style1">aredsterz 2010</p>
</div>
</body>
</html>

save as berjayadihantar.php

jadi.. dari tutorial nie ko leh belajar dua benda.. satu penggunaan script processor dan satu lagi kombinasi php dengan html

saya ade bace komen2 dari pengguna lain, n ade pengguna yang tak tahu bahawa scrpt PHP boleh ber gabung dengan HTML..
 
opppp aku lupe script mailto... sory2
pasnie aku ubah lagi script tue...


aku leh bagi script admin view.. untuk ko tegk contact us yang dah di sent melalui page admin dalam website ko..
 
kalau nak email kan terus form ko tu jus ubah kat action kat ko pnye form jd cam ginei

<form action="mailto:[email protected]" method="post" enctype="text/plain">

<fieldset style="padding: 2">
<legend>Contact us</legend>
Name    :<input type="text" name="name" id="name" size="41"><p>Email    :<input type="text" name="email" id="email" size="41"></p>
<p>Contact No:<input type="text" name="contact" id="contact" size="41"></p>
<p>Message    :</p>
<p><textarea rows="8" name="massage" id="message" cols="46"></textarea></p>
<p> </p>
</fieldset><p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
 
nie satu agi kaedah:
ko tukakan script process.php tu jad script kat bawah nie:

<?php
$to = "[email protected]";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$Contact= $_REQUEST['contact'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Mail anda telah berjaya"; }
else
{print "mail anda tidak ber jaya"; }
?>
 
fuh... thx sgt2 bro aredsterz. aku nak pakai php tu nyer la. sng. tak perlu database kan.
 
hehe tak perlu... ko leh try... die terus sent kat email..
upload je kat server..
kalu nak server free
ko reg kat
freewebhostingarea.com
server nie lengkap.... n ade auto installer...
n asal ade 1 hit per month... akaun server tak kn expired...
:)
thank very2 much for learning ...
 
Back
Top
Log in Register