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 : </td>
<td><input name=”name” type=”text” /></td>
<td> *</td>
</tr>
<tr>
<td>Email : </td>
<td><input name=”email” type=”text” value=”Nhap Mail cua ban” /></td>
<td> *</td>
</tr>
<tr>
<td>Message : </td>
<td><textarea cols=”20″ name=”message” rows=”5″><?php print(“Ban nhap noi dung tai day\n\n”); /* your name */ ?></textarea></td>
<td> *</td>
</tr>
<tr>
<td></td>
<td><input type=”submit” value=”Send” /><input type=”reset” value=”Reset” /></td>
<td></td>
</tr>
<tr>
<td colspan=”3″> </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)