PHP 联系表未发送所有信息

PHP contact form not sending all information

大家好,我正在使用以下脚本作为电子邮件联系表单,当我测试该表单时,它不包括我在电子邮件中添加到表单中的 2 个附加字段(Phone 和公司)收到

对 PHP 很陌生。谁能帮我吗?干杯!

 <?php 
 $action=$_REQUEST['action']; 
 if ($action=="")    /* display the contact form */ 
{ 
?> <div class="input-group">
<form  action="#contact" method="POST" enctype="multipart/form-data"> 
<input type="hidden" name="action" value="submit" > 
<input name="name" type="text" placeholder="Your Name" class="form-control form-control1" />
<input name="email" type="text" placeholder="Email" class="form-control form-control1" />
<input name="phone" type="text" placeholder="Phone" class="form-control form-control1" />
<input name="company" type="text" placeholder="Company" class="form-control form-control1" />
<input name="subject" type="text" placeholder="Subject"  class="form-control form-control1"/>
<textarea name="message" class="form-control" rows="12" placeholder="Let us know what you require"></textarea><br> 
<input type="submit" value="Send Message" class="quoteb" /> 
</form> 
</div>
<?php 
}  
 else                /* send the submitted data */ 
{ 
$name=$_REQUEST['name']; 
$email=$_REQUEST['email']; 
$message=$_REQUEST['phone']; 
$message=$_REQUEST['company']; 
$message=$_REQUEST['message']; 
$message=$_REQUEST['subject']; 
if (($name=="")||($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
    $from="From: $name<$email>\r\nReturn-path: $email"; 
    $subject="$subject"; 
    mail("sales@webxury.com", $subject, $message, $from); 
    echo "Email sent, we will contact you ASAP, thank you"; 
    } 
}   
 ?> 

你每次都在重新定义$message。尝试:

$message = $_REQUEST['phone']; 
$message .= $_REQUEST['company']; 
$message .= $_REQUEST['message']; 
$subject = $_REQUEST['subject'];

最后一个应该是$subject.

我假设缺少的数据是 'phone'、'country' 和 'message'。您正在将这些替换为 $message 的每个分配。你需要看看 string concatenation.

每次您重新分配变量 $message。 取而代之的是,您可以使用以下语法:

 
$message =$_REQUEST['phone'];
$message .=$_REQUEST['company'];
$message .=$_REQUEST['message'];
$message .=$_REQUEST['subject'];

对于换行尝试以下

$message  = $_REQUEST['phone'];
$message .="\n"; 
$message .= $_REQUEST['company']; 
$message .="\n";
$message .= $_REQUEST['message']; 

作为新用户,我没有权限向您的新行查询添加评论,因此请在此处添加。