网站联系表格不发送电子邮件 [英] Website Contact Form Not Sending Email

查看:217
本文介绍了网站联系表格不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近上传了我的第一个网站到iPage服务器。网站运行完美,但联络表格除外,由于某种原因拒绝从表单发送任何电子邮件。
我使用PHP脚本与Post方法,并尝试修复我的代码多次,以纠正我可能输入的任何错误,但到目前为止,无济于事。这是代码:

So I recently uploaded my first website to an iPage server. The website runs perfectly with the exception of the Contact Form which for some reason refuses to send any email whatsoever from the form. I use a PHP Script with the Post Method, and tried to fix my code multiple times to correct any error I might have entered, but so far to no avail. Here is the code:

HTML:
<

HTML: <

form action = "js/mailer.php" form method="post" name="contactform" id="contactform" class="form validate item_bottom" role="form">
                <div class="form-group">
                    <input type="text" name="name" id="name" class="form-control required" placeholder="Name">
                </div>
                <div class="form-group">
                    <input type="email" name="email" id="email" class="form-control required email" placeholder="Email">
                </div>
                <div class="form-group">
                    <textarea name="message" id="message" class="form-control input-lg required" rows="9" placeholder="Enter Message"></textarea>
                </div>
                <div class="form-group text-center">
                    <input type="submit" id="contactForm_submit" class="btn btn-trans btn-border btn-full" value="Submit">
                </div>
        </form>

PHP:

<?php
if(isset($_POST['submit'])) {

$to = "aravindm3095@gmail.com";
$subject = "Hello Aravind!";

// data the visitor provided
$name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email_field = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$comment = filter_var($_POST['message'], FILTER_SANITIZE_STRING);

//constructing the message
$body = " From: $name_field\n\n E-Mail: $email_field\n\n Message:\n\n $comment";

mail($to, $subject, $body);

// redirect to confirmation
header('Location: confirmation.html');

} else {

echo "Failure";

}
?> 

有人可以帮我吗?这可能是我的托管服务器的错误,或我的代码错误。您的帮助非常感谢

Can someone help me with this? It might be an error with my hosting server, or an error with my code. Your help is very much appreciated

附加评论:遵循所提供的帮助(谢谢)我对HTML和PHP进行了必要的更改,但表单仍然是没有功能。它不会回复失败或重定向到确认页面,并且在使用Firefox检查元素时,我注意到,在点击提交按钮后,会出现一个细分,显示发送....。但是没有发送电子邮件,没有邮件被回覆或页面打开。

Additional Comments: Followed the help provided (thank you for that) I made the necessary changes to the HTML and PHP, but the form is still not functional. It does not echo failure or redirect to the confirmation page, and upon inspecting the element with Firefox, I notice that upon hitting the submit button a subdivision appears under it saying "Sending....". But no email is sent, no message is echoed or page opened.

推荐答案

从我发布的代码中我看到的PHP邮件脚本将无法正常工作,因为您正在检查是否存在名称为submit的POST变量,而不是以您的形式提交按钮没有name属性。
尝试给提交按钮一个名称,并将该名称放在PHP if语句中。

From what i see in the code you posted, the PHP mailing script won't work as you are checking if a POST variable with the name 'submit' exists which it does not as in your form the submit button does not have a name attribute. Try giving the submit button a name and put that name in the PHP if statement.

这篇关于网站联系表格不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆