使用 PHPMailer 通过 SMTP 发送邮件
<无详细内容>
# 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
- 下一篇:10 个救命的 PHP 代码片段
精彩图集
精彩文章