0
HTML:不工作PHP的形式在我的網站
<form class="contact-form footer-form" method="post" action="contact.php">
...
</form><!-- /.footer-form -->
contact.php:
<?php
/******************************************************************
* Requirements
******************************************************************/
require_once 'libraries/swift/lib/swift_required.php';
/******************************************************************
* Constants
******************************************************************/
define('MESSAGE_SUBJECT', 'Subject');
define('MESSAGE_FROM_EMAIL', '[email protected]');
define('MESSAGE_FROM_NAME', 'John Doe');
define('MESSAGE_TO_EMAIL', '[email protected]');
define('TRANSPORT_SERVER', 'smtp.example.com');
define('TRANSPORT_PORT', 25);
define('TRANSPORT_USERNAME', 'username');
define('TRANSPORT_PASSWORD', 'password');
/******************************************************************
* Configure transport
******************************************************************/
$transport = Swift_SmtpTransport::newInstance(TRANSPORT_SERVER, TRANSPORT_PORT)
->setUsername(TRANSPORT_USERNAME)
->setPassword(TRANSPORT_PASSWORD);
$mailer = Swift_Mailer::newInstance($transport);
/******************************************************************
* Send email
******************************************************************/
if (!empty($_POST['email']) && !empty($_POST['name']) && !empty($_POST['message'])) {
$body = sprintf("Email: %s \nName: %s\nBody: %s", $_POST['email'], $_POST['name'], $_POST['message']);
$message = Swift_Message::newInstance()
->setSubject(MESSAGE_SUBJECT)
->setFrom(array(MESSAGE_FROM_EMAIL => MESSAGE_FROM_NAME))
->setTo(array(MESSAGE_TO_EMAIL))
->setBody($body);
$mailer->send($message);
}
但是,當我填寫我的形式結束放進入,得到 '未找到contact.php' 錯誤。 (我真正的電子郵件信息在Gmail上,並打開IMAP)我再次檢查了我的細節,一切正常。
我該如何解決?
是contact.php並在同一目錄中的HTML嗎? – Daan
我不知道你的目錄結構是什麼樣的,但試着將它改爲./contact.php。否則,請確保它指向contact.php所在的目錄。 –
Web服務器找不到該文件。檢查所做的請求,檢查它是否映射到服務器上的文件位置,檢查Web服務器的日誌以獲取更多信息,檢查文件權限等。我們可以告訴您的是,Web服務器不認爲「聯繫」。 php'就是你認爲它的地方。 – David