首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

PHPMailer 发送邮件(范例)

2012-09-10 
PHPMailer 发送邮件(实例)1,到官网下载phpmailer的开源代码,http://phpmailer.worxware.com/2,下载完成后,

PHPMailer 发送邮件(实例)

1,到官网下载phpmailer的开源代码,http://phpmailer.worxware.com/

2,下载完成后,找到class.phpmailer.php?、class.smtp.php两个类放到自己的目录下

3,如下例子

<?phprequire_once('class.phpmailer.php');// 开始发送邮件$mail = new PHPMailer(true);$mail->IsSMTP();try {$mail->CharSet = "UTF-8"; // 设置编码$mail->Host = "mail.tms.com.cn"; //邮件服务器// $mail->SMTPDebug = 2;$mail->SMTPAuth = true;$mail->Port = 25;$mail->Username = "dq@shiseido.cn"; // SMTP account username$mail->Password = "12345a"; // SMTP account password$mail->SetFrom('dq@shiseido.cn', 'DQ');$mail->AddReplyTo('dq@shiseido.cn', 'DQ');$mail->Subject = $subject;if($type == 'text') { $mail->Body = $content;} elseif ($type == 'html') {$mail->MsgHTML($content);}for ($i=0; $i < count($addressArray); $i++) {$mail->ClearAddresses();$mail->AddAddress($addressArray[$i]);if($howoften == 1) {sleep(1);} elseif($howoften == 0.5) {if($i%2==0) sleep(1);}// sleep($howoften);$mail->Send();echo "<p>".$addressArray[$i]."</p> <p>is sent.</p>\n";}echo "<p>total ".count($addressArray)." mails is sent.</p>\n";} catch (phpmailerException $e) {  echo $e->errorMessage(); //Pretty error messages from PHPMailer} catch (Exception $e) {  echo $e->getMessage(); //Boring error messages from anything else!}?>
?因为是自己做的一个项目中的一部分,所以代码中有一些发信时的额外要求,请无视~~~

热点排行