无法加载“PHP 电子邮件表单”库

问题描述 投票:0回答:5

由于某种原因,我的 PHP 表单无法工作,当有人按下发送消息按钮时,会弹出此错误“无法加载“PHP 电子邮件表单”库”。我不知道问题是什么。

这是contact.php

<?php

    $receiving_email_address = 'myemailadress';
    
      if( file_exists($php_email_form = '../assets/vendor/php-email-form/php-email-form.php' )) {
        include( $php_email_form );
      } else {
        die( 'Coming Soon!');
      }
    
      $contact = new PHP_Email_Form;
      $contact->ajax = true;
      
      $contact->to = $receiving_email_address;
      $contact->from_name = $_POST['name'];
      $contact->from_email = $_POST['email'];
      $contact->subject = $_POST['subject'];
    
      // Uncomment below code if you want to use SMTP to send emails. You need to enter your correct SMTP credentials
      /*
      $contact->smtp = array(
        'host' => 'example.com',
        'username' => 'example',
        'password' => 'pass',
        'port' => '587'
      );
      */
    
      $contact->add_message( $_POST['name'], 'From');
      $contact->add_message( $_POST['email'], 'Email');
      $contact->add_message( $_POST['message'], 'Message', 10);
    
      echo $contact->send();
    ?>

这是index.html

 <div class="form">
              <form action="forms/contact.php" method="post" role="form" class="php-email-form">
                <div class="row">
                  <div class="form-group col-md-6">
                    <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" required>
                  </div>
                  <div class="form-group col-md-6 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">Send Message</button></div>
              </form>
            </div>

Anf 由于某种原因,文件夹中出现了某种错误日志文件,内容如下:

[19-Nov-2021 13:49:31 UTC] PHP Fatal error:  Uncaught Error: Class 'PHP_Email_Form' not found in /home/domain/public_html/forms/contact.php:16
Stack trace:
#0 {main}
  thrown in /home/domain/public_html/forms/contact.php on line 16
[19-Nov-2021 13:49:32 UTC] PHP Fatal error:  Uncaught Error: Class 'PHP_Email_Form' not found in /home/domain/public_html/forms/contact.php:16
Stack trace:
#0 {main}
  thrown in /home/domain/public_html/forms/contact.php on line 16

我想我应该在第 16 行添加这个 home/domain/public.html/froms/contact.php 但我显然不知道如何正确地做到这一点。

php forms contacts
5个回答
2
投票

或者您可以编写自己的发件人。像这样的东西。

联系.php

$to = '[email protected]';
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);
$from = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$subject = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_SPECIAL_CHARS);
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_SPECIAL_CHARS);

if (filter_var($from, FILTER_VALIDATE_EMAIL)) {
    $headers = ['From' => ($name?"<$name> ":'').$from,
            'X-Mailer' => 'PHP/' . phpversion()
           ];

    mail($to, $subject, $message."\r\n\r\nfrom: ".$_SERVER['REMOTE_ADDR'], $headers);
    die('OK');
    
} else {
    die('Invalid address');
}

2
投票

代码正在此特定目录/文件夹中搜索文件“php-email-form.php”,-> ../assets/vendor/php-email-form/php-email-form.php, 检查那里是否存在所需的 php,否则您需要创建一个并将其放置在那里。


1
投票

您无法在

file_exists()
中分配变量。使用

if( file_exists('../assets/vendor/php-email-form/php-email-form.php')) {
    include('../assets/vendor/php-email-form/php-email-form.php');
} else {
    die( 'Coming Soon!');
}

$php_email_form = '../assets/vendor/php-email-form/php-email-form.php';
if(file_exists($php_email_form)) {
    include($php_email_form);
} else {
    die('Coming Soon!');
}

0
投票

您正在使用免费模板和 PHP 表单 需要“PHP 电子邮件表单”库并且 “PHP 电子邮件表单”库仅在模板的专业版中可用。

您必须购买专业版模板

如果您不想购买,您必须创建自己的 php 代码


0
投票
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'connection.php';
session_start();

$uemail = $_SESSION['Name'];
$sql = "SELECT * FROM contact WHERE Email='$uemail'";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result)>0)
{
    while($row=mysqli_fetch_assoc($result))
    {
        $a=$row["User"];
        $b=$row["Email"];
    }
}

if(isset($_POST['submit']))
{
    $FullName=$_POST['Name'];
    $Feedback=$_POST['Message'];
    
    $emailTo = $_POST["Email"];
    $code = uniqid(true);
    
    $sql = "SELECT * from contact where Email= '$emailTo'";
    $result = mysqli_query($connect,$sql);
/*     $row = mysqli_fetch_assoc($result); */
    
    $result=mysqli_query($connect,"SELECT *FROM contact where Email='$emailTo'");
    $count=mysqli_num_rows($result);
    
    if($count==0)
    {
        ?>
        <script>
            alert("Invalid email address");
        </script>
        <?php
    }
    else
    {
        mysqli_query($connect,"Insert into contact(Name, Email,Subject,Message) Values('$FullName','$emailTo','$subject','$Feedback')");
        // Instantiation and passing `true` enables exceptions
        $mail = new PHPMailer(true);

  /**
  * Requires the "PHP Email Form" library
  * The "PHP Email Form" library is available only in the pro version of the template
  * The library should be uploaded to: vendor/php-email-form/php-email-form.php
  * For more info and help: https://bootstrapmade.com/php-email-form/
  */

  // Replace [email protected] with your real receiving email address
  $receiving_email_address = '[email protected]';

  if( file_exists($php_email_form = '../assets/vendor/php-email-form/php-email-form.php' )) {
    include( $php_email_form );
  } else {
    die( 'Unable to load the "PHP Email Form" Library!');
  }

  $contact = new PHP_Email_Form;
  $contact->ajax = true;
  
  $contact->to = $receiving_email_address;
  $contact->from_name = $_POST['name'];
  $contact->from_email = $_POST['email'];
  $contact->subject = $_POST['subject'];

  // Uncomment below code if you want to use SMTP to send emails. You need to enter your correct SMTP credentials
  /*
  $contact->smtp = array(
    'host' => 'example.com',
    'username' => 'example',
    'password' => 'pass',
    'port' => '587'
  );
  */
  try 
        {
            //Server settings
            $mail->isSMTP();    // Send using SMTP
            $mail->Host       = 'smtp.gmail.com';               // Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
            $mail->Username   = '[email protected]';                     // SMTP username
            $mail->Password   = 'Var#$%67890*&';                               // SMTP password
            $mail->SMTPSecure = 'ssl';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encourageds
            $mail->Port       = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

            //Recipients
            $mail->setFrom('[email protected]', 'Flintex Solution Sdn Bhd');
            $mail->addAddress($emailTo);     // Add a recipient
            $mail->addReplyTo('[email protected]');

            // Content
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = 'Flintex Solution Sdn Bhd';
            $mail->Body    = "Thank you for your interest and scheduling an appointment with our company Flintex Solution Sdn Bhd. We have received your appointment request through our contact form. We are looking forward to meeting with you to discuss the what are your needs or your doubt for a particular services/product.If there's anything specific you'd like us to address during our upcoming appointment or if you have any questions, please feel free to share your preferences by replying to this email. We are eager for your upcoming discussion with us on your needs and preference.";
            $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

            $mail->send();

            echo "<script type='text/javascript'>alert('Thanks for your feedback');</script>";
            header( "refresh:0.5; url=Contact Us.php" );
            
        } 
        catch (Exception $e) 
        {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }
    
    exit(); 
  }
}

  $contact->add_message( $_POST['name'], 'From');
  $contact->add_message( $_POST['email'], 'Email');
  $contact->add_message( $_POST['message'], 'Message', 10);

  echo $contact->send();
?>
I have these code but I am not sure correct or not I added STMP but original got bootstrap so I need 
© www.soinside.com 2019 - 2024. All rights reserved.