THIET KE WEBSITE GIA RE

THIET KE WEBSITE GIA RE

Hướng dẫn làm trang liên hệ – contact bằng PHP

Posted by thietkewebsitegiare on 15/05/2009

Bạn làm một File: contact.php với nội dung như sau:

CODE
<form action=”addmail.inc.php” method=”post”>
<table>
<tr>
<td>Ho & Ten&nbsp;:&nbsp;</td>
<td><input name=”name” type=”text” /></td>
<td>&nbsp;*</td>
</tr>
<tr>
<td>Email&nbsp;:&nbsp;</td>
<td><input name=”email” type=”text” value=”Nhap Mail cua ban” /></td>
<td>&nbsp;*</td>
</tr>
<tr>
<td>Message&nbsp;:&nbsp;</td>
<td><textarea cols=”20″ name=”message” rows=”5″><?php print(“Ban nhap noi dung tai day\n\n”); /* your name */ ?></textarea></td>
<td>&nbsp;*</td>
</tr>
<tr>
<td></td>
<td><input type=”submit” value=”Send” /><input type=”reset” value=”Reset” /></td>
<td></td>
</tr>
<tr>
<td colspan=”3″>&nbsp;</td>
</tr>
<tr>
<td colspan=”3″>Ban phai dien day du cac muc*</td>
</tr>
</table>
</form>

Và một File addmail.inc.php với nội dung sau:
CODE
<?php
$email = $_POST["email"];
$headers = “From: ” . $_POST["email"];
$ip = $_SERVER["REMOTE_ADDR"];
$host = gethostbyaddr($ip);
$message = $_POST["message"];
$name = $_POST["name"];
$subject = “Mail from BanmeOnline.org”; // your webpage
$time = date(“l d F Y @ H:i”);
$to = “nhat@banmeonline.org”; // your email
$message2 = “Email: ” . $email . “\nHost: ” . $host . “\nIP: ” . $ip . “\nMessage: ” . $message . “\nName: ” . $name . “\nTime: ” . $time;

if ($email && $message && $name) {
if (mail($to, $subject, $message2, $headers)) {
print(“Mail cua ban da duoc gui”);
}

else {
print(“The server encountered an unexpected condition which prevented it from fulfilling the request.”);
}
}

else {
print(“Xin ban hay dien day du cac muc co dau *”);
}
?>

//>>

Bạn nên nhớ sửa lại các info cho phù hợp.

Chúc bạn thành công – www.ticsoft.com (Nguồn: sưu tầm)

Gửi phản hồi

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 / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.