【发布时间】:2014-10-10 01:08:54
【问题描述】:
此代码似乎可以在我的 mac localhost 上的 Xampp 中运行,但它似乎不适用于我的免费 000webhost 帐户。我已经尝试摆脱 SSL,但它没有帮助。请记住,此程序从外部表单获取变量。
<?php
$subject = htmlentities($_POST['subject']);
$email = $_POST['email'];
$message = htmlentities($_POST['message']);
require_once 'PHPMailer/PHPMailerAutoload.php';
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
//$m->SMTPDebug = 1;
$m->Host = 'smtp.gmail.com';
$m->Username = 'email-adress@gmail.com';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->From = 'email-adress@gmail.com';
$m->FromName = 'William Green';
$m->addReplyTo('email-adress@gmail.com', 'William Green');
//$m->addCC('email2-address@gmail.com', 'Willliam green');
########################################
//email code
//$recipient = strip_tags($_POST['mailRecipient']);
//$name = strip_tags($_POST['recipientsName']);
$m->addAddress($email, $email);
//$m->Subject = strip_tags($_POST['mailSubject']);
//$m->Body = strip_tags($_POST['mailBody']);
$m->Subject = $subject;
$m->Body = $message;
//$m->AltBody = 'plain text version!';
###########################################
//var_dump($m->send());
if ($m->send())
{
echo '<h1 class="good">Email Sent!</h1>';
}
else
{
echo '<h1 class="bad">Email Not Sent!</h1>';
}
?>
【问题讨论】:
-
000webhost 在处理网站时并不是那么好;他们的服务器可能在黑名单中,或者他们可能会阻止传出的 SMTP 端口以防止垃圾邮件。也许是时候换一个更好的虚拟主机了,或者您可以节省时间并让自己拥有一个虚拟专用服务器来不受限制地托管您的需求。
-
你可以在端口 587 上尝试 TLS。