繁体   English   中英

我的PHP / HTML表格不起作用

[英]My PHP/HTML form doesn't work

我的网站上有联系表格,但该表格无法正常运行。 我收到了电子邮件,但是电子邮件为空,我没有从表单中获取信息。

我的index.html中的html部分

<form role="form" form name="contactform" method="post" action="send_form_email.php"> 
                 <div class="form-group">
                        <label>Nombre</label> <input type="text" name="nombre" class="form-control" placeholder="Introduce tu nombre" >
                  </div>
                 <div class="form-group">
                        <label>Apellidos</label> <input type="text" name="apellidos" class="form-control" placeholder="Introduce tus apellidos" >
                  </div>
                 <div class="form-group">
                        <label>Email</label> <input type="emal" name="email" class="form-control" placeholder="Introduce tu email" >
                  </div>
                 <div class="form-group">
                        <label>Telefono</label> <input type="text" name="telefono" class="form-control" placeholder="Introduce tu telefono" >
                  </div>

                  <div class="form-group">
                        <label>Mensaje</label> <textarea name="mensaje" class="form-control" rows="7"></textarea>
                  </div>

                     <button type="submit" class="btn btn-default" value="Submit">   <a href="send_form_email.php">Enviar</a>
                 </form>

                </div>

php文件中名为“ send_form_email.php”的部分

    <?php
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$telefono = $_POST['telefono'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
$formcontent=" $nombre $apellidos $email $telefono $mensaje";
$recipient = "deniz946@gmail.com";
$subject = "Subject from $nombre";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will get back to you as soon as possible!" . " -" . "<a href='./index.php'> Back to site</a>";
?>

<input type="emal" name="email" class="form-control" placeholder="Introduce tu email" >更改为

<input type="email" name="email" class="form-control" placeholder="Introduce tu email" >

您在type属性中有错字。

尝试这个

<?php
$nombre      = $_POST['nombre'];
$apellidos   = $_POST['apellidos'];
$telefono    = $_POST['telefono'];
$email       = $_POST['email'];
$mensaje     = $_POST['mensaje'];
$formcontent = "{$nombre} {$apellidos} {$email} {$telefono} {$mensaje}";
$recipient   = "deniz946@gmail.com";
$subject     = "Subject from $nombre";

if(PHP_OS == "Linux" || PHP_OS == "Darwin") $new_line = "\n"; /* if Linux or Mac */
elseif(PHP_OS == "WINNT") $new_line = "\r\n"; /* if Windows */
$mailheader  = "MIME-Version: 1.1" . $new_line;
$mailheader .= "Content-type: text/html; charset=utf-8" . $new_line;
$mailheader .= "From: ".$recipient.$new_line;
$mailheader .= "Return-Path: " . $recipient . $new_line;
$mailheader .= "Reply-To: " . $recipient . $new_line;

mail($recipient, $subject, $formcontent, $mailheader, "-r" . $recipient) or die("Error!");
echo "Thank You! We will get back to you as soon as possible!" . " -" . "<a href='./index.php'> Back to site</a>";
?>

也许我可以帮我举个例子:

HTML联系人表格:

            <div class="row">

                <!-- Content -->
                    <div id="content" class="8u skel-cell-mainContent">
                        <section class="12u">

                            <header>
                                <h2>Contact</h2>
                            </header>

                         <form method="post" action="mail.php">
                        <div class="row half">
                            <div class="6u">
                                <input name="subject" placeholder="Name" type="text" class="text" />
                            </div>
                            <div class="6u">
                                <input name='email' placeholder="Email" type="text" class="text" />
                            </div>
                        </div>
                        <div class="row half">
                            <div class="12u">
                                <textarea name="message" placeholder="Message"></textarea>
                            </div>
                        </div>
                        <div class="row half">
                            <div class="12u">
                                <!--a href="mail.php" class="button">Submit</a-->
                                <input type="submit" class="button" value="Submit">
                            </div>
                        </div>
                    </form>

                        </section>

                    </div>

PHP的处理形式:

<?php 
                //mail(to,subject,message,headers,parameters)


                    // Check if the "from" input field is filled out
                    //if (isset($_POST['from'])) 
                    //{}
                      $to = 'mail@xxxxxx.com'; // my email address
                      $subject = $_POST['subject']; //name client

                      $feedback = 'thank you, we will reply soon.';
                      $header  = $_POST['email']; //Email client

                      $message = $_POST['message'];
                      $message = wordwrap($message, 70);

                      $message = <<<EMAIL
Dear (YOUR WEBSITE NAME HERE),

My name is: $subject

$message

Email Client: $header


EMAIL;





                      // send mail
                      if($_POST){ 
                      mail($to, $subject, $message, $header);

                      echo $feedback;
                                }





?>

切记,从Dear ...到EMAIL的部分必须靠在屏幕左侧,没有任何标签或空格。 否则它将无法正常工作!

希望你可以用它来成功:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM