發表新文章 回覆主題  [ 2 篇文章 ] 

討論區首頁 : 資訊專區 : PHP程式設計

發表人 內容
 文章主題 : PHP在Email上的應用
文章發表於 : 2011年 10月 31日, 13:14 
離線
系統管理員

註冊時間: 2009年 1月 14日, 06:05
文章: 1419
1.HTML 程式碼
<html><body><font face=Arial size=2>
<form method="post" action="contact.php">
<table bgcolor=#ffffcc align=center>
<tr><td colspan=2><strong>Contact us using this form:</strong></td></tr>
<tr><td>Department:</td><td><select name="sendto"> <option value="info@mycompany.com">General</option> <option value="support@mycompany.com">Support</option> <option value="sales@mycompany.com">Sales</option> </select></td></tr>
<tr><td><font color=red>*</font> Name:</td><td><input size=25 name="Name"></td></tr>
<tr><td><font color=red>*</font> Email:</td><td><input size=25 name="Email"></td></tr>
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr>
<tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr>
<tr><td>Subscribe to<br> mailing list:</td><td><input type="radio" name="list" value="No"> No Thanks<br> <input type="radio" name="list" value="Yes" checked> Yes, keep me informed<br></td></tr>
<tr><td colspan=2>Message:</td></tr>
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr>
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr>
<tr><td colspan=2 align=center><small>A <font color=red>*</font> indicates a field is required</small></td></tr>
</table>
</form>
</body>
</html>
========================================

2.PHP 程式碼
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@YourCompany.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.YourDomain.com/thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
}
}
?>
=====================================
3.表單的類型

There are ten specific types of INPUT tag in HTML 4.01 and HTML5 adds 13 new ones. the HTML 4.01 types are:

button
checkbox
file
hidden
image
password
radio
reset
submit
text
======================================


Back to top
 個人資料  
 
 文章主題 : Re: PHP在Email上的應用
文章發表於 : 2011年 10月 31日, 13:19 
離線
系統管理員

註冊時間: 2009年 1月 14日, 06:05
文章: 1419
1.html
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>

2.php
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "yourname@example.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
?>


Back to top
 個人資料  
 
顯示文章 :  排序  
發表新文章 回覆主題  [ 2 篇文章 ] 

討論區首頁 : 資訊專區 : PHP程式設計


誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客


不能 在這個版面發表主題
不能 在這個版面回覆主題
不能 在這個版面編輯文章
不能 在這個版面刪除文章
不能 在這個版面上傳附加檔案

搜尋:
前往 :  
cron
Style by Midnight Phoenix & N.Design Studio
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
正體中文語系由 竹貓星球 維護製作