Reputation: 53
I am having issues with a contact form in the website I am working. My php
file where the code to send the mail is run does not work. When the user clicks the submit button it shows in the screen the code 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 = '[email protected]';
$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>';
}
}
?>
Upvotes: 3
Views: 119
Reputation: 38
I 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're currently working on isn't safe at all. Many bots can submit the form automatically and can send you numerous of spam emails. The way to prevent these, is to use a security captcha verification which totally prevents these bots from submitting your form. If you're interested in a secured form, get in touch with me as I'll write one for you free-of-charge :)
I know there is a way where you can process mails using if(mail) statements, but there's numerous scripts like PHPMailer which can do the trick for you easily. If you're processing this contact-form on a web-server, then it's most likely to be in their hosting-configuration faults. If you're using Localhost (eg: WAMP), try doing that way to ensure if it works on your self-set server, if it does then it's most likely to be a faulty web-server you're currently running on.
PS: I'm a PHP Script Developer, developed more than 25 scripts.
Upvotes: 1