douke3442 2014-04-18 07:41
浏览 36
已采纳

注意:未定义的变量:第9行中的MESSAGE_BODY

I have a simple contact page set up with a form and I am sending those details via email using the php mail() function. When I submit the page its die and says:

Notice: Undefined variable: MESSAGE_BODY in line 9

Anybody has any idea or solution please?

 <?php
 error_reporting(E_ALL); 
if ($_POST["email"]<>'') {
    $ToEmail = 'saif0909@yahoo.com';
    $EmailSubject = 'Get an instant Quote Now';
    $mailheader = "From: ".$_POST["email"]."
";
    $mailheader .= "Reply-To: ".$_POST["email"]."
";
    $mailheader .= "Content-type: text/html; charset=iso-8859-1
";
    $MESSAGE_BODY .= "Company Name".$_POST['companyname']."";
    $MESSAGE_BODY = "First Name: ".$_POST["firstname"]."";
    $MESSAGE_BODY = "Last Name: ".$_POST["lastname"]."";
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."";
    $MESSAGE_BODY = "Phone Number: ".$_POST["phone"]."";
    $MESSAGE_BODY = "Delivery City: ".$_POST["city"]."";
    $MESSAGE_BODY = "Delivery Date: ".$_POST["date"]."";
    $MESSAGE_BODY = "Duration: ".$_POST["duration"]."";
    $MESSAGE_BODY .= "Rental Equipment: ".nl2br($_POST["msg"])."";
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
 ?>

 Your message was sent
<?php
} else {
?> 
 <aside>
          <form action="./" method="post" class="form-c">
            <fieldset>
              <legend>Get an Instant Quote Now</legend>
             <p>
              <label for="companyname">Company Name</label>
              <input type="text" id="companyname" name="companyname" required>
            </p>
             <p>
              <label for="firstname">First Name</label>
              <input type="text" id="firstname" name="firstname" required>
            </p>
             <p>
              <label for="lastname">Last Name</label>
              <input type="text" id="lastname" name="lastname" required>
            </p>
             <p>
              <label for="email">Email Address</label>
              <input type="email" id="email" name="email" required>
            </p>
            <p>
              <label for="phone">Phone</label>
              <input type="number" id="phone" name="phone" required>
            </p>
             <p>
              <label for="city">Delivery City</label>
              <input type="text" id="city" name="city" required>
            </p>
             <p>
              <label for="date">Delivery Date</label>
              <input type="text" id="date" name="date" required>
            </p>
            <p>
              <label for="durationa">Duration</label>
              <input type="text" id="duration" name="duration" required>
            </p>

            <p>
              <label for="msg">Enter Rental Equipment</label>
              <textarea id="msg" required="" name="msg"></textarea>
            </p>

              <p class="submit"><button type="submit" name="submit">Proceed</button></p>
            </fieldset>
          </form>

          <?php
};
?>

        </aside> 
  • 写回答

4条回答 默认 最新

  • doulao2029 2014-04-18 08:02
    关注

    Use isset. Fisrt line should be:

    if (isset($_POST["email"]) && $_POST["email"] != "") {
    

    This will trigger a short-cirtuit evaluation of && and the second condition will not cause error if the "email" field is not sent.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程