PHP电子邮件表单不发送textarea

时间:2015-07-04 15:34:46

标签: php email

我在PHP中有一个简单的电子邮件表单,用于将表单输入发送到电子邮件地址。但是,textarea不包括在内。电话号码正在发送,只有textarea不发送。这是我的表格:

<form id="form1" name="form1" method="post" action="send.php">
<p>  <span id="sprytextfield1">Your name:
  <label for="name"></label>
  <input type="text" name="name" id="name" /></p>
  <span class="textfieldRequiredMsg">A value is required.</span></span>
  <p><span id="sprytextfield2">
    <label for="email">Email address:</label>
    <input type="text" name="email" id="email" />
    <span class="textfieldRequiredMsg">A value is required.</span></span></p>
  <p>
    <label for="phone">Phone Number:</label>
    <input type="text" name="phone" id="phone" />
  </p>

  <p><span id="sprytextarea1">
    <label for="message">Message</label>
    <br />
    <textarea name="message" id="message" cols="45" rows="5"></textarea>
  <span class="textareaRequiredMsg">A value is required.</span></span></p>
  <p>
    <input type="submit" name="Submit" id="Submit" value="Submit" />
    <br />
  </p>
</form>

之后,我对表单进行了验证。 这是php

$name=$_POST[name];
$email=$_POST[email];
$phone=$_POST[phone];
$message=$_POST[message];

$from="From: $name<$email>\r\nReturn-path: $email"; 
       $subject="Message sent using your contact form"; 
      mail("my@email.com", $subject, $from, $phone, $message); 
    echo "Email sent!"; 

3 个答案:

答案 0 :(得分:2)

改变你的

$name=$_POST[name];
$email=$_POST[email];
$phone=$_POST[phone];
$message=$_POST[message];

$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$message=$_POST['message'];

您的信息将以这种方式运作

答案 1 :(得分:0)

嗯,你没有按正确的顺序使用参数。根据邮件文档(http://php.net/manual/en/function.mail.php),它应该是:

mail("my@email.com", $subject, $message, $from); 

我不确定您要使用$phone的位置,但可能在发送之前可以将其连接到$message

答案 2 :(得分:0)

出于某种原因,这很有用。使用$ subject,$ message,$ from只会发送消息。我摆脱了电话号码。

$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];

  $from="From: $name<$email>\r\nReturn-path: $email"; 
        $subject="Someone from your website is contacting you"; 
        mail("me@email.com", $subject, $from, $message); //weird, but it works