PHP联系人表单提交失败,未从以下位置返回错误消息:forms/contact.php

xzv2uavs  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(118)

我面临的问题,在我的联系表格,我想发送邮件使用php上点击发送消息按钮,我得到错误的形式提交失败没有错误

<div class="col-lg-6 mt-5 mt-lg-0" data-aos="fade-left" data-aos-delay="100">

        <form action="forms/contact.php" method="post" role="form" class="php-email-form">
          <div class="row">
            <div class="col-md-6 form-group">
              <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" required>
            </div>
            <div class="col-md-6 form-group mt-3 mt-md-0">
              <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" required>
            </div>
          </div>
          <div class="form-group mt-3">
            <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" required>
          </div>
          <div class="form-group mt-3">
            <textarea class="form-control" name="message" rows="5" placeholder="Message" required></textarea>
          </div>
          <div class="my-3">
            <div class="loading">Loading</div>
            <div class="error-message"></div>
            <div class="sent-message">Your message has been sent. Thank you!</div>
          </div>
          <div class="text-center"><button type="submit" name="submit" id="submit">Send Message</button></div>
        </form>

      </div>

这是我的php代码,我保存在contact.php下的forms文件夹。

<?php  error_reporting(E_ALL); ini_set('display_errors', 1);
$result = "";
$error  = "";
if(isset($_POST['submit']))
{
$name = $_POST['name']; // Get Name value from HTML Form
$email_id = $_POST['email']; // Get Email Value
     
$to = "[email protected]"; // You can change here your Email
$subject = $_POST['subject']; // This is your subject
     
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//smtp settings
$mail->isSMTP(); // send as HTML
$mail->Host = "smtpout.secureserver.net"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "************"; // Your mail
$mail->Password = '************'; // Your password mail
$mail->Port = 465; //specify SMTP Port
$mail->SMTPSecure = 'ssl\tls';                               
$mail->setFrom($email_id,$name);
$mail->addAddress('**********');
$mail->addReplyTo($email_id,$name);
$mail->isHTML(true);
$mail->Subject=$subject;
$mail->Body="
    <html>
        <body>
            <table style='width:600px;'>
                <tbody>
                    <tr>
                        <td style='width:150px'><strong>Name: </strong></td>
                        <td style='width:400px'>$name</td>
                    </tr>
                    <tr>
                        <td style='width:150px'><strong>Email ID: </strong></td>
                        <td style='width:400px'>$email_id</td>
                    </tr>
                    <tr>
                        <td style='width:150px'><strong>Message: </strong></td>
                        <td style='width:400px'>$msg</td>
                    </tr>
                </tbody>
            </table>
        </body>
    </html>
    ";;
if(!$mail->send())
{
    $error = "Something went worng. Please try again.";
}
else 
{
    $result="Thanks\t" .$name. " for contacting us.";
}

}
?>
我已经添加了phpmailer文件到

请帮助我解决和理解这个问题

des4xlb0

des4xlb01#

您的错误消息不是php错误。在contact.php页面上启用php错误并向我们显示准确的错误。您可以通过转到php.ini文件并启用所有错误来实现这一点。另外,暂时注解掉你的mail函数,以确保php正在获取表单数据。

相关问题