PHPMailer 本机不需要安装SMTP Server就能发邮件

PHP自带的函数mail()不能满足大家的需要,于是便有了phpmailer,有了它操作邮件就简单多了,使用它自带的class可以收发自如.下面是我使用的自己的163邮箱发送到自己的gmail邮箱的代码
<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');
//date_default_timezone_set(date_default_timezone_get());

include_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth=true;
$mail->Host       = "smtp.163.com"; // SMTP server
$mail->Username   = "bubble1000";
$mail->Password   = "密码不能写哦";

$mail->From       = "[email protected]";
$mail->FromName   = "First Last";

$mail->Subject    = "PHPMailer Test Subject via smtp";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAddress("[email protected]", "John Doe");

$mail->AddAttachment("images/phpmailer.gif");             // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

?>



这段代码是我根据其中的test_smtp.php改的.附件是phpmailer的zip文件,或者可以到sourceforge.net上搜搜. ,会有新发现的哦!

你可能感兴趣的:(html,.net,PHP,Gmail)