php帶抄送和密件抄送的郵件發(fā)送方法
來(lái)源:易賢網(wǎng) 閱讀:1355 次 日期:2015-03-23 14:12:07
溫馨提示:易賢網(wǎng)小編為您整理了“php帶抄送和密件抄送的郵件發(fā)送方法”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了php帶抄送和密件抄送的郵件發(fā)送方法,涉及php中mail函數(shù)的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php帶抄送和密件抄送的郵件發(fā)送方法。分享給大家供大家參考。具體分析如下:

程序中用到了php的mail函數(shù),該函數(shù)定義如下:

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

如果郵件發(fā)送成功返回True,否則返回False

<html>

<head>

<title>Send email with CC and BCC</title>

</head>

<body>

<form action="sendemail.php" method=post name=form1>

<table>

<tbody>

<tr>

<td>

<div align=right><b>To</b></div></td>

<td>

<p>Name <input name=mailtoname size=35><br />E-mail

<input name=mailtomail size=35></p></td></tr>

<tr>

<td>

<div align=right><b>CC</b></div></td>

<td><input name=mailcc size=35> </td></tr>

<tr>

<td>

<div align=right><b>BCC</b></div></td>

<td><input name=mailbcc size=35> </td></tr>

<tr>

<td>

<div align=right><b>Priority</b></div></td>

<td><select name=mailpriority>

<option value=1>Highest</option>

<option value=2>High</option>

<option selected value=3>Normal</option>

<option value=4>Low</option>

<option value=5>Lowest</option>

</select>

</td></tr>

<tr>

<td><div align=right><b>Subject</b></div></td>

<td><input name=mailsubject size=35></td></tr>

<tr>

<td>

<div align=right><b>Message</b> </div></td>

<td><textarea cols=50 name=mailbody rows=7></textarea></td></tr>

<tr>

<td colSpan=2>

<div align=center>

<input name=Submit type=submit value=Submit></div>

</td>

</tr>

</tbody>

</table>

</form>

</body>

</html>

后端php代碼,保存為sendmail.php

<html>

<head>

<title>Send Mail Script</title>

</head>

<body>

<?php

$message= " " ;

if (empty ( $mailtoname) || empty ( $mailtomail) ) {

die ( "Recipient is blank! ") ;

}else{

$to = $mailtoname . " <" . $mailtomail . ">" ;

}

if ( empty ( $mailsubject) ) {

$mailsubject=" ";

}

if (($mailpriority>0) && ($mailpriority<6)) {

$mailheader = "X-Priority: ". $mailpriority ."\n";

}

$mailheader.= "From: " . "Sales Team <";

$mailheader.= "X-Sender: " . "";

$mailheader.= "Return-Path: " . "";

if (!empty($mailcc)) {

$mailheader.= "Cc: " . $mailcc ."\n";

}

if (!empty($mailbcc)) {

$mailheader.= "Bcc: " . $mailbcc ."\n";

}

if (empty($mailbody)) {

$mailbody=" ";

}

$result = mail ($to, $mailsubject, $mailbody, $mailheader);

echo "<center><b>Mail sent to ". "$to". "<br />";

echo $mailsubject. "<br />";

echo $mailbody. "<br />";

echo $mailheader. "<br />";

if ($result) {

echo "<p><b>Email sent successfully!</b></p>";

}else{

echo "<p><b>Email could not be sent. </b></p>";

}

?>

<div align="center">

<table><tr><td width="66"><div align="right"><b>To</b></div></td>

<td width="308"><b>

<?php echo $mailtoname . " [". $mailtomail . " ]";?>

</b></td></tr>

<tr><td width="66"><div align="right"><b>CC</b></div></td>

<td width="308"><b><?php echo $mailcc;?></b></td></tr>

<tr><td width="66"><div align="right"><b>BCC</b></div></td>

<td width="308"><b><?php echo $mailbcc; ?></b></td></tr>

<tr><td width="66"><div align="right"><b>Priority</b></div></td>

<td width="308"><b><?php echo $mailpriority;?></b></td></tr>

<tr><td width="66"><div align="right"><b>Subject </b></div></td>

<td width="308"><b><?php echo $mailsubject;?></b></td></tr>

<tr><td width="66"><div align="right"><b>Message</b></div></td>

<td width="308"><b><?php echo $mailbody;?></b></td></tr>

</table>

</div>

</body>

</html>

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:php帶抄送和密件抄送的郵件發(fā)送方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)