-1
I am creating a form to send e-mail direct from a website, through the PHP
. However, when I add the field to put the phone to contact the code PHP
, You don’t seem to recognize the field, and you don’t get the information from that field.
I ran some tests on the code on PHP
and if I put some other variable in the phone field the same appears in the email and if I use the phone field in another variable the same does not appear the information.
Code in PHP:
<?php
// Check for empty fields
if(empty($_POST['phone']) &&
empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "Campo preenchido incorretamente!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = '[email protected]'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "E-mail enviado por $name";
$email_body = "E-mail de contato enviado por $name \n";
$email_body .= "\nNome: $name
\nTelefone: $phone
\nE-mail: $email_address
\nMensagem:\n $message \n";
$headers = "From: $email_address\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
HTML:
<form name="sentMessage" id="contactForm" action="contact_me.php" method="post">
<!--name="sentMessage" id="contactForm" novalidate-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" id="name" name="name" class="form-control" placeholder="Nome" required="required">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="email" id="email" name="email" class="form-control" placeholder="E-mail" required="required">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="text" id="phone" name="phone" class="form-control" placeholder="Telefone" required="required">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<textarea name="message" id="message" name="message" class="form-control" rows="4" placeholder="Mensagem" required></textarea>
<p class="help-block text-danger"></p>
</div>
<div id="success"></div>
<button type="submit" class="btn btn-default">Enviar</button>
</form>
missing the name of inputs in almost all!
– novic