问题描述
此代码似乎可以在Mac本地主机上的Xampp中运行,但似乎无法在我的免费000webhost帐户上运行.我已经尝试摆脱SSL,但没有帮助.请记住,该程序从外部形式获取变量.
This code seems to work in Xampp on my mac localhost but it doesn't seem to work on my free 000webhost account. I already tried getting rid of SSL but it didn't help. Keep in mind that this program get variables from an external form.
<?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 protected]';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->From = '[email protected]';
$m->FromName = 'William Green';
$m->addReplyTo('[email protected]', 'William Green');
//$m->addCC('[email protected]', '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>';
}
?>
推荐答案
A :他们不不提供SMTP免费托管.改用PHP的 mail()
函数.
A: They do not offer SMTP for free hosting. Use PHP's mail()
function instead.
请注意其站点上SMTP服务器旁边的红色x
=> http://www.000webhost.com /吗?
Notice the red x
next to SMTP Server on their site => http://www.000webhost.com/ ?
使用 mail()
或付款,以便使用SMTP.
Either use mail()
or pay for it in order to use SMTP.
您可以在他们的网站上进行操作,也可以在控制面板内进行升级.
You can do it on their website, or upgrade from within the control panel.
编辑(2016年9月16日):此答案是在他们改版网站之前发布的.可在此处查看免费/收费服务可用选项的URL,网址为 https://www.000webhost.com/premium-web-hosting
Edit (Sept. 16, 2016): This answer was posted before they revamped their website. The URL where you can see the available options for free/paid services, can be see here https://www.000webhost.com/premium-web-hosting
这也适用于与数据库的远程连接.
This also goes for remote connections to a database.
此答案是针对我今天看到的一个与我的编辑相关的问题进行编辑的.
This answer was edited in regards to a question I saw today which was related to my edit.
这篇关于PHPMailer在000webhost上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!