I am trying to send an html form entry to my email via PHP but it is not working. Here is my HTML code for the contact form:
<form action="assets/php/consultationmail.php" method="post">
<div >
<input type="text" name="name" placeholder="Full Name" required>
</div>
<div >
<input type="email" name="email" placeholder="[email protected]" required>
</div>
<div >
<input type="tel" name="Phone" placeholder="0245678910" required>
</div>
<div >
<input type="textarea" name="message" placeholder="Message" required>
</div>
<div >
<button type="submit" value="submit" >Get Consultations
<i ></i></button>
</div>
</form>
and here's my PHP code
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$email_from = "[email protected]";
$email_subject = "New Consultation Request";
$email_body = "A visitor has request for a consultation. Details are below <br>" . "Name:" $name "<br>" ."Email:" $email "<br>" . "Phone:" $phone "<br>" . "Message:" $message "<br>"
$to = "[email protected]";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
What am I doing wrong please?
CodePudding user response:
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$email_from='[email protected]';
$email_subject='New Consultation Request';
$email_body='A visitor has request for a consultation.<br>Details are below<br>Name:'.$name.'<br>Email:'.$email.'<br>Phone:'.$phone.'<br>Message:'.$message.'<br>';
$to='[email protected]';
$to=$to;
$subject=$email_subject;
$message=$email_body;
$headers='From:'.$email_from."\r\n".'Reply-To:'.$email."\r\n".'X-Mailer:PHP/'.phpversion();
mail($to,$subject,$message,$headers);
CodePudding user response:
You forgot to close your $email_body statement with an ;