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

时间:2014-04-18 07:41:18

标签: php email sendmail

我有一个简单的联系页面设置表格,我使用php mail()功能通过电子邮件发送这些详细信息。 当我提交页面时,它会说:

  

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

有人有任何想法或解决方案吗?

 <?php
 error_reporting(E_ALL); 
if ($_POST["email"]<>'') {
    $ToEmail = 'saif0909@yahoo.com';
    $EmailSubject = 'Get an instant Quote Now';
    $mailheader = "From: ".$_POST["email"]."\r\n";
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $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 个答案:

答案 0 :(得分:1)

使用isset。 Fisrt行应该是:

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

这将触发&amp;&amp; amp;&amp;如果&#34;电子邮件&#34;并且第二个条件不会导致错误字段未发送。

答案 1 :(得分:0)

请在php脚本的顶部添加$MESSAGE_BODY=''。有点像这样。

<?php
 error_reporting(E_ALL); 
if (isset($_POST["email"])) {
    $MESSAGE_BODY='';  //<-- this line
    $ToEmail = 'saif0909@yahoo.com';
    $EmailSubject = 'Get an instant Quote Now';
    $mailheader = "From: ".$_POST["email"]."\r\n";
    $mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
    $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $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"); 
 ?>

答案 2 :(得分:0)

试试这个

  

的error_reporting(E_ALL);
  if($ _POST [&#34; email&#34;]&lt;&gt;&#39;&#39;){
     $ ToEmail =&#39; saif0909@yahoo.com' ;;
     $ EmailSubject =&#39;立即获取报价&#39;;
     $ mailheader =&#34;来自:&#34;。$ _ POST [&#34; email&#34;]。&#34; \ r \ n&#34;;
     $ mailheader。=&#34;回复:&#34;。$ _ POST [&#34; email&#34;]。&#34; \ r \ n&#34;;
     $ mailheader。=&#34;内容类型:text / html;字符集= ISO-8859-1 \ r \ n&#34 ;;
     $ MESSAGE_BODY =&#39;&#39;;
      $ MESSAGE_BODY。=&#34;公司名称&#34;。$ _ POST [&#39;公司名称&#39;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;名字:&#34;。$ _ POST [&#34;名字&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;姓氏:&#34;。$ _ POST [&#34;姓氏&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;电子邮件:&#34;。$ _ POST [&#34;电子邮件&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;电话号码:&#34;。$ _ POST [&#34;电话&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;交货城市:&#34;。$ _ POST [&#34; city&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;交货日期:&#34;。$ _ POST [&#34; date&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;持续时间:&#34;。$ _ POST [&#34;持续时间&#34;]。&#34;&#34 ;;
     $ MESSAGE_BODY。=&#34;租赁设备:&#34; .nl2br($ _ POST [&#34; msg&#34;])。&#34;&#34 ;;
     邮件($ ToEmail,$ EmailSubject,$ MESSAGE_BODY,$ mailheader)或死亡(&#34;失败&#34;);

答案 3 :(得分:0)

您可以在MESSAGE_BODY的第一个声明中删除连接,并将连接(。=)添加到将文本添加到$ MESSAGE_BODY的所有其他行。 $ MESSAGE_BODY的第一个应该是:$ MESSAGE_BODY = ....其余的应该是这样的 $ MESSAGE_BODY。= ...