无法使用PHP发送HTML表单条目



我试图通过PHP发送一个html表单条目到我的电子邮件,但条目是空的。这是我的HTML代码的联系方式:

<form action="assets/php/consultationmail.php" method="post">
<div class="input-field">
<input type="text" name="name" placeholder="Full Name" required>
</div>
<div class="input-field">
<input type="email" name="email" placeholder="you@youremail.com" required>
</div>
<div class="input-field">
<input type="tel" name="Phone" placeholder="0245678910" required>
</div>
<div class="input-field">
<input type="textarea" name="message" placeholder="Message" required>
</div>
<div class=" input-field">
<button type="submit" value="submit" class="template-btn">Get Consultations
<i class="far fa-long-arrow-right"></i></button>
</div>
</form>
这是我的PHP代码
<?php
<?php
$subject = 'New Consultation Request'; // Subject of your email
$to = 'myemail@gmail.com';  //Recipient's E-mail
$emailTo = $_REQUEST['email'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$msg = $_REQUEST['message'];
$email_from = $name.'<'.$email.'>';
$headers = "MIME-Version: 1.1";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: ".$name.'<'.$email.'>'."rn"; // Sender's E-mail
$headers .= "Return-Path:"."From:" . $email;
$message .= 'Name : ' . $name . "n";
$message .= 'Email : ' . $email . "n";
$message .= 'Phone : ' . $phone . "n";
$message .= 'Message : ' . $msg;
if (@mail($to, $subject, $message, $email_from))
{
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
else
{
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
?>

这是我收到邮件的结果:

,

& lt的在

Name: Email: Phone: Message:

请问我做错了什么?
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];
$email_from='noreply@company.com';
$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='company@gmail.com';    
$to=$to;
$subject=$email_subject;
$message=$email_body;
$headers='From:'.$email_from."rn".'Reply-To:'.$email."rn".'X-Mailer:PHP/'.phpversion();
mail($to,$subject,$message,$headers);

您忘记用;结束$email_body语句

相关内容

  • 没有找到相关文章

最新更新