PHP电源表单不会将所有字段发送到电子邮件

时间:2014-01-30 21:23:26

标签: php forms email

我使用这个php脚本在用户提交表单时将表单内容发送到我的电子邮箱,但目前我只能将表单的最后两个字段发送到电子邮件中。(消息和公司名称)是唯一的两个工作)我怎样才能通过电子邮件发送整个表格?

<form role="form" method='post' action='backend/php_mailer.php'>
<input type="text" name='name' class="form-control" id="yourname" placeholder="Name">
<input type="email" name='email' class="form-control" id="email" placeholder="Email">
<input type="text" name='phone' class="form-control" id="phone" placeholder="Phone">
<input type="text" name='company' class="form-control" id="company" placeholder="Company Name">
<textarea name='message' class="form-control" id="message" rows="6" placeholder="Message"></textarea>
<button type="submit" class="btn btn-primary btn-lg ">SUBMIT</button>
</form>




<?php
if (isset($_POST['email']))

  {

   $userName = $_REQUEST['name'] ; 
   $email = $_REQUEST['email'] ; 
   $phone = $_REQUEST['phone'] ;
   $company = $_REQUEST['company'] ;
   $message = $_REQUEST['message'] ;
   mail("peaceuponelove@gmail.com", $subject,
   $message,$company,$userName );
   echo "Thank you";
   }

  ?>

2 个答案:

答案 0 :(得分:2)

mail()的每个论点都有特定的目的。您不能只是不断传递参数并期望将它们附加到电子邮件中。您必须使用字符串连接。

$message = $_REQUEST['message'] . '</br>' . $email . '<br/>' . $phone . '<br/> ' . $userName . '<br/> . ' $company;
mail("peaceuponelove@gmail.com", $subject,$message);

Sidenote 您从未在已显示的代码中声明$subject。所以这是一个主题:

$subject = 'Message from '. $userName .' < ' . $email . ' > ';

答案 1 :(得分:0)

以下是我最终要通过电子邮件获取所有字段

<?php


?>
<form  action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<input name="name" type="text" value="" size="30"/><br>
<input name="email" type="text" value="" size="30"/><br>
<input name="phone" type="text" value="" size="30"/><br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Send email"/>
</form>
<?php

$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$phone=$_REQUEST['phone'];
$message=$_REQUEST['message'].$email.$phone;



    $subject="$name";
    mail("peaceuponelove@gmail.com", $subject, $message);
    echo "Email sent!";

?>