dph6308 2014-05-09 04:28
浏览 73

网站联系表格不发送电子邮件

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: <

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

 E-Mail: $email_field

 Message:

 $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

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.

  • 写回答

3条回答 默认 最新

  • dongmu9253 2014-05-09 04:33
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路