大家好,由于某種原因,我的 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 但我顯然不知道如何正確添加。
你能幫我嗎 ?
uj5u.com熱心網友回復:
您不能在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!');
}
uj5u.com熱心網友回復:
如果您從模板的免費版本下載這些代碼,那么它將無法作業。您需要一個 PHP 電子郵件表單庫。如果您檢查您的assets/vendor/php-email-form/,您將缺少 php-email-form.php 檔案。據我所知,您必須購買才能獲得該檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/366641.html
