【发布时间】:2017-02-05 12:13:32
【问题描述】:
我花了几天时间才得到正确的设置,所以我想我会发布一个适用于 Bluehost 的 php 脚本。在初始测试中,使用 isSMTP 比 isMAIL 更快。
<?php
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "box1311.bluehost.com"; // specify bluehost as outgoing server
$mail->SMTPSecure = "tls"; // sets the prefix to the server do not use ssl
$mail->SMTPDebug = 3; // comment out if you don't need debug info
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "USER@EXAMPLE.COM"; // SMTP username (your email account)
$mail->Password = "PASSWORD"; // SMTP password
$mail->Port = 25;
$mail->From = 'USER@EXAMPLE.COM';
$mail->FromName = "USER@EXAMPLE.COM";
$mail->AddAddress('CLIENT@gmail.com');
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = 'test message';
$body = '<!DOCTYPE html>
<html><header>
</header>
<body lang=EN-US>
<div style="text-align:center">
<h2>this is a test</h2>
</div>
</body>
</html>';
$mail->Body = $body;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()){
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo '<h1>message sent</h1>';
}
?>
【问题讨论】:
-
如果这是一个解决方案,您应该发布一个(可搜索的)问题,然后在上面发布您的贡献作为实际答案。 You are permitted to answer your own questions,然后会看到一个复选框,上面写着 您想回答自己的问题吗?(或类似的内容)。
-
非常感谢!帮了我很多!
标签: php smtp phpmailer shared-hosting