phppear mail發送郵件實例
- -->
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>php發送郵件</title>
- </head>
- <body>
- <table width="611" height="200" border="1">
- <tr>
- <td width="601"><form id="form1" name="form1" method="post" action="send.php">
- <table width="600" height="240" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td width="102" height="28">收件人地址</td>
- <td width="213"><input name="to" type="text" id="to" /></td>
- <td width="84">發送人地址</td>
- <td width="201"><input name="from" type="text" id="from" value="cert@163.com" /></td>
- </tr>
- <tr>
- <td height="33">發送人用戶名</td>
- <td><input name="name" type="text" id="username" value="cert" /></td>
- <td>郵箱密碼</td>
- <td><input name="password" type="password" id="password" value="***" /></td>
- </tr>
- <tr>
- <td height="27">smtp服務器</td>
- <td><input name="smtp" type="text" id="smtp" value="smtp.163.com" /></td>
- <td colspan="2">注:163郵箱smtp為: smtp.163.com</td>
- </tr>
- <tr>
- <td height="26">標題</td>
- <td colspan="3"><input name="subject" type="text" id="subject" value="cert測試php發送郵件" size="50" /></td>
- </tr>
- <tr>
- <td height="69">內容</td>
- <td colspan="3"><textarea name="content" cols="50" rows="6" id="content">計算機緊急響應組歡迎你!
- http://www.49028c.com
- 組織網站即將進行改版</textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td align="right"><input type="submit" name="submit" value="發送" /></td>
- <td> </td>
- <td> </td>
- </tr>
- </table>
- <p>說明:我用163的郵箱發給 163 或 126 的郵箱立刻就能收到。大家試試。</p>
- </form>
- </td>
- </tr>
- </table>
- </body>
- </html>
- <?
- require_once 'mail.php';
- $conf['mail'] = array(
- 'host' => 'smtp.126.com', //smtp服務器地址
- 'auth' => true, //true表示smtp服務器需要驗證,false不需要
- 'username' => 'liangbowen', //用戶名
- 'password' => '******' //密碼
- );
- //發送郵件
- $headers['from'] = 'liangbowen@126.com'; //發信地址
- $headers['to'] = 'liangbowen@hotmail.com'; //收信地址
- $headers['subject'] = 'test mail send by php bowen.mvbb.com'; //郵件標題
- $mail_object = &mail::factory('smtp', $conf['mail']);
- //郵件正文
- $body = "這是一封自己發給自己的郵件。";
- $mail_res = $mail_object->send($headers['to'], $headers, $body); //發送
- if(pear::iserror($mail_res)){ //檢測錯誤
- die($mail_res->getmessage());
- }
- else{
- echo "send successful!";
- }
新聞熱點
疑難解答