最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > php教程 >

php 发送邮件代码

时间:2014-06-09 16:40来源: 作者: 点击: 次
本文章是利用phpmailer来实现在线发送邮件功能的源码代码. !DOCTYPEhtmlPUBLIC -//W3C//DTDXHTML1.0Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd htmlxmlns= http://www.w3.org/1999/xhtml head metahttp-equiv= C

本文章是利用phpmailer来实现在线发送邮件功能的源码代码.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <title>--邀请好友参加</title> 
  6. <style type="text/css"> 
  7. <!-- 
  8. body { 
  9.  margin: 0px; 
  10.  padding: 0px; 
  11.  font-size: 12px; 
  12.  background-color: #CFCFCF; 
  13. } 
  14. input { 
  15.  line-height: 18px; 
  16.  height: 18px; 
  17.  border: 1px solid #CCCCCC; 
  18. } 
  19. img { 
  20.  border-top-width: 0px; 
  21.  border-right-width: 0px; 
  22.  border-bottom-width: 0px; 
  23.  border-left-width: 0px; 
  24. } 
  25. * { 
  26.  margin: 0px; 
  27.  padding: 0px; 
  28.  list-style-image: none; 
  29.  list-style-type: none; 
  30.  background-repeat: no-repeat; 
  31. } 
  32. td { 
  33.  line-height: 22px; 
  34.  font-size: 14px; 
  35.  font-weight: 700; 
  36.  color: #276662; 
  37. } 
  38. --> 
  39. </style> 
  40. </head> 
  41. <body> 
  42. <form action="#" method="post" name="form"> 
  43. <table border="0" align="center" cellpadding="0" cellspacing="0"> 
  44.   <tr> 
  45.     <td width="572" height="227" valign="top" background="img/mailfooterimg.gif"><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> 
  46.       <tr> 
  47.         <td height="70">&nbsp;</td> 
  48.       </tr> 
  49.       <tr> 
  50.         <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> 
  51.           <tr> 
  52.             <td><input type="text" value="http://111cn.net/" size="60" /></td> 
  53.             <td height="40"><a href="#"><img src="img/copy.gif" width="72" height="22" /></a></td> 
  54.           </tr> 
  55.         </table></td> 
  56.       </tr> 
  57.       <tr> 
  58.         <td height="28">好友姓名: 
  59.           <input type="text" size="22" /> 
  60.           &nbsp;&nbsp; 
  61.           邮箱地址: 
  62.           <input type="text" size="22" />        </td> 
  63.       </tr> 
  64.       <tr> 
  65.         <td height="28">好友姓名: 
  66.           <input type="text" size="22" /> 
  67.           &nbsp;&nbsp; 
  68.           邮箱地址: 
  69.           <input type="text" size="22" />        </td> 
  70.       </tr> 
  71.       <tr> 
  72.         <td height="28">好友姓名: 
  73.           <input type="text" size="22" /> 
  74.           &nbsp;&nbsp; 
  75.           邮箱地址: 
  76.           <input type="text" size="22" />        </td> 
  77.       </tr> 
  78.       <tr> 
  79.         <td height="28" align="right"><a href="#"><img src="img/sendbtn.gif" width="95" height="26" /></a></td> 
  80.       </tr> 
  81.     </table></td> 
  82.   </tr> 
  83. </table> 
  84. </form> 
  85. </body> 
  86. </html> 

发送邮件处理功能页面mail.php

  1. <? 
  2. require(dirname(__FILE__)."/mail/class.phpmailer.php"); //调用 phpmailer类型,如果没有phpmailer请点击这里下载phpmailer for php5/6 下载 
  3. $array =  array_unique(Get_value('mail',1));//去除重复的邮箱地址 
  4. $mail = new PHPMailer();  
  5.  $count =0;  
  6.  $bad =0; 
  7.  $mail->IsSMTP();                                      // set mailer to use SMTP 
  8.  $mail->Host = "smtp.163.com";  // smtp1.example.com;smtp2.example.comspecify main and backup server 
  9.  $mail->SMTPAuth = true;     // turn on SMTP authentication 
  10.  $mail->Username = "mailangel123";  // SMTP username 
  11.  $mail->Password = "*******"; // SMTP password 
  12.  
  13.  $mail->From = "mailangel123@163.com"; 
  14.  $mail->FromName = "你的好友来信"; 
  15.  $MailBody = '内容' 
  16. $mail->AddReplyTo("mailangel123@163.com", "澳优"); 
  17.    $mail->AddAddress($tmpmail,'您好!'); 
  18.    $mail->WordWrap = 50; 
  19.    $mail->CharSet="GB2312";                                  
  20.    //$mail->AddAttachment("/var/tmp/file.tar.gz");         
  21.    //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    
  22.    $mail->IsHTML(true); 
  23.    $mail->Subject = "你的朋友邀请你一起合影!"; 
  24.    $mail->Body    = $MailBody; 
  25.    if(!$mail->Send()) 
  26.    { 
  27.       $bad++; 
  28.       $mail->ClearAddresses();    
  29.       $mail->ClearAttachments();  
  30.    } 
  31. OK就完成了哦。 
  32. ?> 
(责任编辑:admin)
------分隔线----------------------------
栏目列表
推荐内容