【问题标题】:Trouble with PHPPHP的问题
【发布时间】:2015-12-09 05:50:00
【问题描述】:

我是 PHP 新手。基本上我是一名平面设计师转为前端设计师。我知道 html css 和简单的 jquery。我需要将此联系表包含在网站中,但似乎不起作用。请帮忙。如果有人可以指出代码是否有任何问题,那将是很大的帮助。 提前致谢。

这是联系表格的 html 部分:

<div class="form">  

<form action="mail.php" method="POST">
<label>Name</label>
<br>
<input type="text" name="name" placeholder="Type Here">
    <br><br><br>
<label>Email</label>
<br>
<input type="email" name="email" placeholder="Type Here">
  <br><br><br>
<label>Message</label>
<br>
<textarea name="message" rows="20" cols="20" placeholder="Type Here">    </textarea>
    <br><br><br>
<label>*What is 2+2? (Anti-spam)</label>
<br>
<input type="text" name="human" placeholder="Type    
 <br><br><br><br>
 <input id="submit" name="submit" type="submit" value="SUBMIT">
</form>

这是php:

<?php
$name = $_POST['name'];
$email = $_POST['email'];

$message = $_POST['message'];
$formcontent=" From: $name \n Message: $message";
$recipient = "saurabhdey84@gmail.com";
$subject = "Vibhor Sogani Website Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! Your message has been sent." . "-" . <a href='home.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

【问题讨论】:

  • 您没有提到实际的错误是什么,但这是我在您的代码中发现的错误:Parse error: syntax error, unexpected '&lt;' in /opt/lampp/htdocs/phptry/rough.php - 错过了双引号!

标签: php html forms contact


【解决方案1】:

像这样改变你的回声,

echo "Thank You! Your message has been sent." . "- <a href='home.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
                                                ^// no need of contenation here

【讨论】:

    【解决方案2】:

    如果您正在调用 php 页面,它只是采用空白值,请尝试这些更改并告诉我,

    include_once("home.html");
    if(isset($_POST['submit']))
    {
    **Your php code here**
    }
    

    【讨论】:

      【解决方案3】:

      HTML

      将文本控件更改为

      <input type="text" name="human" placeholder="Type the answer"/>
      

      检测到格式错误:

      <input type="text" name="human" placeholder="Type    
       <br><br><br><br>
       <input id="submit" name="submit" type="submit" value="SUBMIT">
      

      PHP: 最后的 echo 语句应该是这样的:(missed double-quotes)

      echo "Thank You! Your message has been sent." . "-" . "<a href='home.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
      

      不是这样的:

      echo "Thank You! Your message has been sent." . "-" . <a href='home.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
      

      为了更好:

      echo "Thank You! Your message has been sent. - <a href='home.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
      

      这里不需要任何连接!

      【讨论】:

        【解决方案4】:

        通过回显 $_POST['name'] 检查您的 POSTS 是否正在发送到服务器脚本。如果是 ,那么是 mail() 函数的问题。 您正在使用默认的 php mail() 函数。如果没有正确的标题,它就无法工作。我看到您只使用了一个“回复发件人”标头。因此您需要更深入地研究使用邮件函数()。发送电子邮件的替代方案可能是广泛使用的 phpmailer 库

        【讨论】:

        • 谢谢。我要去看看这个。
        【解决方案5】:

        试试这个,并在输入的结束标记处加上 required

                <?php 
           if(isset($_POST['submit']))
        
              {
        
          $name = $_POST['name'];
          $email = $_POST['email'];
          $message = $_POST['message'];
        
           $to = "maild@gmail.com";
        
        
        
              $subject = " contact form" ;
              $headers .= "MIME-Version: 1.0\r\n";
              $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                 $mesg = '$name  $email  $message';
             $kk=mail($to,$subject,$mesg,$headers);
               if($kk){
              ?>
        
             <script>
        
             window.location.href='thankyou.html';
                </script>
        
                 }
        
            }
        
             ?>
        

        【讨论】:

          【解决方案6】:

          通常是这样的

          $headers = "MIME-Version: 1.0" . "\r\n";
          $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
          $headers .= 'From: <webmaster@example.com>' . "\r\n";
          $headers .= 'Cc: myboss@example.com' . "\r\n";
          

          就像我之前说的,phpmailer 库是一个更可靠的替代品

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2011-01-18
            • 2014-07-18
            • 2011-02-22
            • 2016-07-04
            • 2011-05-10
            • 2016-09-19
            • 2012-01-18
            相关资源
            最近更新 更多