php 使用 PHPMailer 通过 SMTP 发送邮件
使用 PHPMailer 通过 SMTP 发送邮件 **[PHP]代码**```{.php}# Include PHP Mailer Classrequire_once(quot;class.phpmailer.phpquot;);# Create object of PHPMailer$mail = new PHPMailer();// Inform class to use SMTP$mail-gt;IsSMTP();
[PHP]代码
# 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!";
}
- 上一篇:php得到当前页面的完整地址
- 下一篇:php解压缩zip文件
精彩图集
精彩文章






