Nikas_Zalias Posted September 15, 2015 Share Posted September 15, 2015 (edited) Hello, I have this small html and php files and the problem is I can't send any emails... When I press submit it just opens php file on the browser. Can anyone help me? Here is the code <html> <link href="style.css" rel="stylesheet" type="text/css"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Contact Form</title> </head> <body> <header class="body"> </header> <section class="body"> <form method="post" action="mail.php"> <label>Name</label> <input name="name" placeholder="Type Here"> <label>Email</label> <input name="email" type="email" placeholder="Type Here"> <label>Message</label> <textarea name="message" placeholder="Type Here"></textarea> <label>*What is 2+2? (Anti-spam)</label> <input name="human" placeholder="Type Here"> <input id="submit" name="submit" type="submit" value="Submit"> </form> </section> <footer class="body"> </footer> </body> </html> <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: TangledDemo'; $to = 'myemail@gmail.com'; $subject = 'Hello'; $human = $_POST['human']; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; if ($_POST['submit']) { if ($name != '' && $email != '') { if ($human == '4') { if (mail ($to, $subject, $body, $from)) { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } } else if ($_POST['submit'] && $human != '4') { echo '<p>You answered the anti-spam question incorrectly!</p>'; } } else { echo '<p>You need to fill in all required fields!!</p>'; } } ?> Edited September 15, 2015 by Nikas_Zalias Quote Link to comment https://forums.phpfreaks.com/topic/298179-cant-send-email-with-php-script-in-html-form/ Share on other sites More sharing options...
QuickOldCar Posted September 15, 2015 Share Posted September 15, 2015 Do you have a server with php installed? If doing it locally is many AMP stacks can choose from. https://en.wikipedia.org/wiki/List_of_Apache%E2%80%93MySQL%E2%80%93PHP_packages Popular ones are WAMP and XAMPP btw, this should be in the head section <link href="style.css" rel="stylesheet" type="text/css"> Quote Link to comment https://forums.phpfreaks.com/topic/298179-cant-send-email-with-php-script-in-html-form/#findComment-1520889 Share on other sites More sharing options...
hansford Posted September 15, 2015 Share Posted September 15, 2015 I agree with QuickOldCar, PHP doesn't appear to be parsing the file. The PHP engine needs to be installed before that can happen. I use WAMP as it packaged with all I need for a localhost development environment. Quote Link to comment https://forums.phpfreaks.com/topic/298179-cant-send-email-with-php-script-in-html-form/#findComment-1520891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.