龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

使用 PHPMailer 通过 SMTP 发送邮件

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
<无详细内容>
# Include PHP Mailer Class
require_once("class.phpmailer.php");

# Create object of PHPMailer
$mail = new PHPMailer();

// Inform class to use SMTP
$mail->IsSMTP();

// Enable this for Testing
$mail->SMTPDebug  = 2;

// Enable SMTP Authentication
$mail->SMTPAuth   = true;

// Host of the SMTP Server
$mail->Host = "host.smtpserver.com";

// Port of the SMTP Server
$mail->Port = 25;

// SMTP User Name
$mail->Username   = "user@smtpserver.com";

// SMTP User Password
$mail->Password = "user_pass";

// Set From Email Address
$mail->SetFrom("from@yourdomain.com", "From Name");

// Add Subject
$mail->Subject    = "PHPMailer SMTP Testing";

// Add the body for mail
$body = "This is the mail body";
$mail->MsgHTML($body);

// Add To Address
$to "info@yourdomain.com";
$mail->AddAddress($to, "SMTP Test");


// Finally Send the Mail
if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "Message sent Successfully!";
}
精彩图集

赞助商链接