Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在我的网站上使用PHP表单_Php_Html_Forms - Fatal编程技术网

无法在我的网站上使用PHP表单

无法在我的网站上使用PHP表单,php,html,forms,Php,Html,Forms,HTML: ... contact.php: <form class="contact-form footer-form" method="post" action="contact.php"> ... </form><!-- /.footer-form --> 您引用的这两个文件是否在同一目录中?尝试将contact.php更改为/contact.php,如下所示 <?php /*********************************

HTML:


...
contact.php:

<form class="contact-form footer-form" method="post" action="contact.php">
...
</form><!-- /.footer-form -->

您引用的这两个文件是否在同一目录中?尝试将contact.php更改为/contact.php,如下所示

<?php

/******************************************************************
 * Requirements
 ******************************************************************/
require_once 'libraries/swift/lib/swift_required.php';

/******************************************************************
 * Constants
 ******************************************************************/
define('MESSAGE_SUBJECT', 'Subject');
define('MESSAGE_FROM_EMAIL', 'john@doe.com');
define('MESSAGE_FROM_NAME', 'John Doe');
define('MESSAGE_TO_EMAIL', 'john@doe.com');

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);
}

或者,只需要一个完整的uri

<form class="contact-form footer-form" method="post" action="/contact.php">


contact.php和html是否在同一个目录中?我不知道您的目录结构是什么样子,但请尝试将其更改为./contact.php。否则,请确保它指向contact.php所在的目录。web服务器找不到该文件。检查正在发出的请求,检查它是否映射到服务器上的文件位置,检查web服务器的日志以获取更多信息,检查文件权限等。我们可以告诉您的是,web服务器认为contact.php
不是您认为的位置。谢谢朋友们。但是,contact.php是根目录,因此contact.php和html位于同一目录中。
<form class="contact-form footer-form" method="post" action="FULLURL/contact.php">