Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...