CS学生在第一个网站上工作,在hostinger上与phpmailer有问题
我终于建立了我的第一个网站,并得到了托管计算。正如标题“我在使用hostinger和phpmailer”中所述,我从未使用过PHP,因此我阅读了他们的简短教程,并以正确的方式设置了PHP文件 我遇到的问题是,当我提交表单时,我会看到一个错误页面。chrome上的网络选项卡中没有任何内容表明它正在尝试发送任何数据,尽管它确实显示它正在打开PHP文件,我想,这也是我的第一个网站,也是第一次使用PHP PHP:CS学生在第一个网站上工作,在hostinger上与phpmailer有问题,php,html,Php,Html,我终于建立了我的第一个网站,并得到了托管计算。正如标题“我在使用hostinger和phpmailer”中所述,我从未使用过PHP,因此我阅读了他们的简短教程,并以正确的方式设置了PHP文件 我遇到的问题是,当我提交表单时,我会看到一个错误页面。chrome上的网络选项卡中没有任何内容表明它正在尝试发送任何数据,尽管它确实显示它正在打开PHP文件,我想,这也是我的第一个网站,也是第一次使用PHP PHP: <?php use PHPMailer\PHPMailer\PHPMailer; r
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'hostinger-email@domain.com';
$mail->Password = 'password for hostinger email';
$mail->setFrom('same-as-username??', 'Admin');
$mail->addAddress('destination@gmail.com', 'Savannah');
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
$mail->Subject = 'PHPMailer contact form';
$mail->isHTML(false);
$mail->Body = <<<EOT
Email: {$_POST['email']}
Name: {$_POST['name']}
Message: {$_POST['message']}
EOT;
if (!$mail->send()) {
$msg = 'Sorry, something went wrong. Please try again later.';
} else {
$msg = 'Message sent! Thanks for contacting us.';
}
} else {
$msg = 'Share it with us!';
}
?>
<header class="form_header">Contact Me</header>
<form id="form" class="topBefore" action="/domains/piecesofblonde.com/public_html/formscript.php" method="post">
<input id="name" type="text" placeholder="NAME">
<input id="email" type="text" placeholder="E-MAIL">
<textarea id="message" type="text" placeholder="MESSAGE"></textarea>
<input id="submit" type="submit" value="GO!">
</form>
HTML表单:
<?php
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'hostinger-email@domain.com';
$mail->Password = 'password for hostinger email';
$mail->setFrom('same-as-username??', 'Admin');
$mail->addAddress('destination@gmail.com', 'Savannah');
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
$mail->Subject = 'PHPMailer contact form';
$mail->isHTML(false);
$mail->Body = <<<EOT
Email: {$_POST['email']}
Name: {$_POST['name']}
Message: {$_POST['message']}
EOT;
if (!$mail->send()) {
$msg = 'Sorry, something went wrong. Please try again later.';
} else {
$msg = 'Message sent! Thanks for contacting us.';
}
} else {
$msg = 'Share it with us!';
}
?>
<header class="form_header">Contact Me</header>
<form id="form" class="topBefore" action="/domains/piecesofblonde.com/public_html/formscript.php" method="post">
<input id="name" type="text" placeholder="NAME">
<input id="email" type="text" placeholder="E-MAIL">
<textarea id="message" type="text" placeholder="MESSAGE"></textarea>
<input id="submit" type="submit" value="GO!">
</form>
联系我
“我得到一个错误页面”,上面写着。。。什么?将表单操作属性更改为just/formscript.php
,您似乎在中缺少一个起始单引号addAddress@nice_dev他们走了!这是给出的错误代码,我知道这与我的文件结构或链接到PHP文件的方式有关,但我不知道它的确切含义。@nice_dev Awe man,我的hostinger服务器上没有composer。我以为它是预装在所有的计划,但不是一个,我有。我将手动安装它,然后返回给您。谢谢大家的帮助