Create a contact form

I am having problems with the contact form on the website I work on. My file php

running the code to send mail is not working. When the user clicks the submit button, he shows the code on the screen and does not send the email.

Html

<header class="body1">
</header>

<section class="body1">
</section>

<footer class="body1">
</footer>

<form method="post" action="index.php">
<h2>Envie uma mensagem ou faรงa um pedido</h2>
<label>Nome:</label>
<input name="name" placeholder="Digite seu nome...">

<label>Email:</label>
<input name="email" type="email" placeholder="Digite seu email...">

<label>Mensagem:</label>
<textarea name="message" placeholder="Digite sua mensagem..."></textarea>

<input id="submit" name="submit" type="submit" value="submit">

</form>

      

PHP

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'De: Babylon Store'; 
$to = 'my@email.com'; 
$subject = 'Novo pedido';

$body = "De: $name\n E-Mail: $email\n Message:\n $message";

if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Sua mensagem foi enviada!</p>';
} else { 
    echo '<p>Aconteceu algo errado. Por favor tente novamente!</p>'; 
}
}

?>

      

+3


source to share


1 answer


I've tried the codes myself and it doesn't work.

Never used: if (mail) , try using mail ($ to, $ subject, $ body, $ from)

Although the contact form you are currently working on is not secure. Many bots can automatically submit a form and can send you a lot of spam emails. The way to prevent this is to use a security check that completely prevents these bots from being sent. If you are interested in a secure form, please contact me as I will write for you for free :)



I know that you can process emails with if (mail) statements , but there are many scripts out there like PHPMailer that can do the trick easily. If you are processing this contact form on a web server, then it will most likely be in your host configuration errors. If you are using Localhost (ex: WAMP) try this to make sure it works on your self-configuring server, if it does it will most likely be the faulty web server you are currently running.

PS: I am a PHP Script developer, I have developed over 25 scripts.

+1


source







All Articles