【问题标题】:Sending email with data from form发送包含表单数据的电子邮件
【发布时间】:2013-08-20 08:29:09
【问题描述】:

我对简单的联系人框有疑问。我想将表单中的信息发送到我的电子邮件。

已经尝试过打开和关闭注册全局变量 (.httacess),尝试使用简单的 $formname 和 $_POST['formname'] 但仍然收到没有表单信息的电子邮件。

<?php

        if ($action == "send"){//isset wyslij




    //if (!$name || !$email || !$phone || !$enquiry) {
        //$problem = TRUE;
       //echo("<p>You have to fill all form.</p>");
    //}     

    if (!$problem){


    $name = $_POST['name'];    
    $data = date("d.m.y");


    $message = "
    <p>Name: $name</p>
    <p>Phone: $phone</p>
    <p>Email: $email</p>
    <br>
    <p>Enquiry: $enquiry</p>";


$od = "blabla@email.com";
$content = $message;
$header = "From: $od \r\n";
$header  .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
     (mail('myemail@gmail.com', 'New message from website Angelzena', $content, $header));



                     echo("<br><p>Message has been sent.</p>");

    }else{
          echo("<p>Try <a href=contact.php>again</a></p>");
         }                    
}


?>



        <form action="contact.php?action=send" method="post" enctype="text/plain">
        <label  for="name">Name</label><input type="text" name="name" /></br></br>
        <label  for="email">Email</label><input type="text" name="email" /></br></br>
        <label  for="phone">Phone</label><input type="text" name="phone" /></br></br>
        <label  for="enquiry">Enquiry</label><textarea name="enquiry" cols="20" rows="10"></textarea></br></br>
        <input type="submit" id="contact_button" value="Send" />
        </form>

【问题讨论】:

  • 您的脚本没有获得除name 之外的任何输入字段,除非您遗漏了部分脚本。
  • 忘记 register_globals!你绝对不应该使用它。通过$_POST['email'] 访问您的表单值
  • 我试过这样 $name = $_POST['name'];,但我没有在电子邮件中获得名称值,所以这仍然不起作用。

标签: php html forms contact-form


【解决方案1】:

&lt;form action="contact.php?action=send" method="post" enctype="text/plain"&gt;

当 POST 表单时,enctype 属性应该是 application/x-www-form-urlencoded 或 multipart/form-data。

PHP 不处理以text/plain 形式发布的表单。

【讨论】:

  • 很好看。由于没有文件组件,enctype 应该被省略。
猜你喜欢
  • 2013-04-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-08
  • 1970-01-01
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
  • 2020-04-22
相关资源
最近更新 更多