Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

php - Website Contact Form Not Sending Email

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...