php提交表單發(fā)送郵件的方法
更新時間:2015年03月20日 10:13:26 作者:work24
這篇文章主要介紹了php提交表單發(fā)送郵件的方法,實例分析了php操作表單發(fā)送郵件的技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了php提交表單發(fā)送郵件的方法。分享給大家供大家參考。具體如下:
保存下面的html代碼到:email.html文件
<html>
<head>
<title>Simple Send Mail </title>
</head>
<body>
<h1>Mail Form</h1>
<form name="form1" method="post" action="mail.php">
<table>
<tr><td><b>To</b></td><td>
<input type="text" name="mailto" size="35">
</td></tr>
<tr><td><b>Subject</b></td>
<td><input type="text" name="mailsubject" size="35"></td>
</tr>
<tr><td><b>Message</b></td>
<td>
<textarea name="mailbody" cols="50" rows="7"></textarea>
</td>
</tr>
<tr><td colspan="2">
<input type="submit" name="Submit" value="Send">
</td>
</tr>
</table>
</form>
</body>
</html>
后端php代碼,保存到mail.php
<?php
if (empty ($_POST['mailto']) ) {
die ( "Recipient is blank! ") ;
}
if (empty ($_POST['$mailsubject']) ){
$mailsubject=" " ;
}
if (empty ($_POST['$mailbody']) ) {
$mailbody=" " ;
}
$result = mail ($mailto, $mailsubject, $mailbody) ;
//send the email
if ($result) {
echo "Email sent successfully!" ;
}else{
echo "Email could not be sent." ;
}
?>
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
php下foreach提示W(wǎng)arning:Invalid argument supplied for foreach()
這篇文章主要介紹了php下foreach提示W(wǎng)arning:Invalid argument supplied for foreach()的解決方法,是很多開發(fā)者在進行PHP程序設(shè)計的過程中經(jīng)常會遇到的問題,需要的朋友可以參考下2014-11-11
php中利用explode函數(shù)分割字符串到數(shù)組
這篇文章主要介紹了php中利用explode函數(shù)分割字符串到數(shù)組,需要的朋友可以參考下2014-02-02
PHP幾個數(shù)學(xué)計算的內(nèi)部函數(shù)學(xué)習(xí)整理
下面主要講述 round, floor, ceil, pow, rand,max, min, decbin, bindec, dechex, hexdec, decoct, octdec 函數(shù)。2011-08-08
快速解決PHP調(diào)用Word組件DCOM權(quán)限的問題
下面小編就為大家分享一篇快速解決PHP調(diào)用Word組件DCOM權(quán)限的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12
原生JS實現(xiàn)Ajax通過POST方式與PHP進行交互的方法示例
這篇文章主要介紹了原生JS實現(xiàn)Ajax通過POST方式與PHP進行交互的方法,涉及ajax使用post方式與后臺交互及php數(shù)據(jù)接收、處理、查詢數(shù)據(jù)庫等相關(guān)操作技巧,需要的朋友可以參考下2018-05-05

