doumu5662 2014-06-26 10:18
浏览 44

PHP mail()函数发送空变量

For some reason name, email and message appear empty when I receive an email.

HTML

<form method="post" action="send.php" class="form-horizontal">
<fieldset>
    <!-- Text input-->
    <div class="form-group">
        <label class="col-md-4 control-label" for="name">Name</label>
        <div class="col-md-4">
            <input id="name" name="name" type="text" class="form-control input-md" required="">
        </div>
    </div>
    <!-- Text input-->
    <div class="form-group">
        <label class="col-md-4 control-label" for="email">Email</label>
        <div class="col-md-4">
            <input id="email" name="email" type="email" class="form-control input-md" required="">
        </div>
    </div>
    <!-- Textarea -->
    <div class="form-group">
        <label class="col-md-4 control-label" for="message">Message</label>
        <div class="col-md-4">
            <textarea class="form-control" id="message" name="message"></textarea>
        </div>
    </div>
    <!-- Button -->
    <div class="form-group">
        <label class="col-md-4 control-label" for="submit"></label>
        <div class="col-md-4">
            <button id="submit" name="submit" type="submit" value="Submit" class="btn btn-outline-inverse btn-lg">Submit</button>
        </div>
    </div>
</fieldset>
</form>

PHP Code Simplified example

 <?php

$emailto  = "example@example.com";
$subject  = "Example subject";
$name     = Trim(stripslashes($_POST['name']));
$email    = Trim(stripslashes($_POST['email']));
$message  = Trim(stripslashes($_POST['message']));
$headers  = "From: example@example.com
";
$headers .= "Reply-To: example@example.com
";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "
";

$body = "<p>You have received a new message:</p>
              <p><strong>Ime: </strong> {$name} </p>
              <p><strong>Email Address: </strong> {$email} </p>
              <p><strong>Poruka: </strong> {$message} </p>";

$success = mail($emailto, $subject, $body, $headers);


if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

For some reason variables $name, $email and $message appear empty when I receive an email from this contact form/mail function. The rest is shown correctly.

  • 写回答

3条回答 默认 最新

  • dougou5844 2014-06-26 10:21
    关注

    You also need to close the " in the $body variable.

    $body = "<p>You have received a new message:</p>
             <p><strong>Ime: </strong> {$name} </p>
             <p><strong>Email Address: </strong> {$email} </p>
             <p><strong>Poruka: </strong> {$message} </p>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据