Php 为什么我会收到';无法打开流';从联系人表单提交数据时出错?
我已经创建了一个HTML5联系人表单,目前正在使用Swiftmailer在本地主机(XAMPP)上进行测试,单击submit按钮后出现以下错误:Php 为什么我会收到';无法打开流';从联系人表单提交数据时出错?,php,swiftmailer,Php,Swiftmailer,我已经创建了一个HTML5联系人表单,目前正在使用Swiftmailer在本地主机(XAMPP)上进行测试,单击submit按钮后出现以下错误: Warning: require_once(/swift.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php on line 10 Warning: requir
Warning: require_once(/swift.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php on line 10
Warning: require(/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/testsite/swift.php on line 20
显然,第10行引用了我的PHP中的require_once行,但是在我的文件中它被封装在HTML标记中
我相信这个错误告诉我该文件不存在,但它确实存在,我可以毫无问题地浏览它
我的HTML文件和'swift.php'
文件本身都在/Applications/XAMPP/xamppfiles/htdocs/testsite/
中,因此我不确定为什么会出现此错误。我尝试了以下方法:
require_once(realpath(dirname(__文件).'swift.php')代码>没有成功
我还尝试了许多呈现文件路径的排列(例如。/
),包括完整的文件路径,但也没有成功
我的HTML(form.HTML)
是:
<form id="contactform" name="contact" method="post" action="sendmessage.php">
<label for="Name">Name: *</label><br>
<input type="text" name="Name" id="Name"><br>
<label for="Email">Email: *</label><br>
<input type="Email" name="Email" id="Email" class="txt"><br>
<label for="Message">Message: *</label><br>
<textarea name="Message" rows="20" cols="20" id="Message" class="txtarea"></textarea><br>
<button type="submit" id="submit-button">Send E-mail</button>
</form>
“生成的密码”是使用谷歌的两步验证时需要的特定于应用程序的密码,但这里当然已经删除了
我已经研究了以下问题,但我似乎已经执行了给出的建议
我已尝试将'require_once(/swift.php”);
修改为'require_once(/swift.php”);
,但这会导致以下错误:
Warning: require_once(/swift.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php on line 10
Warning: require(/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/testsite/swift.php on line 20
不同之处在于现在路径中添加了一个“classes”子文件夹。将'swift.php'
放入该文件夹会产生原始错误
参考第20行为:
$data = "Name: " . $name . "<br />" . "Email: " . $usermail . "<br />" . "Message: " . $content;
在swift.php的第20行:
require(dirname(__FILE__)."/classes/Swift.php");
require(dirname(__FILE__)."/classes/Swift.php");
检查和重新运行后出现的错误是:
Warning: require(/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/classes/Swift.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php on line 20
每次我添加一个“类”文件夹时,它似乎都在寻找一个额外的“类”文件夹。尝试更改
require_once("/swift.php");
到
尝试改变
require_once("/swift.php");
到
尝试改变
require_once("/swift.php");
到
尝试改变
require_once("/swift.php");
到
错误消息显示:
警告:require_once(/swift.php):无法打开流:没有这样的文件或目录
你声称:
我相信这个错误告诉我该文件不存在,但它确实存在,我可以毫无问题地浏览它
你所谓的证据是:
我的HTML文件和“swift.php”文件本身都位于/Applications/XAMPP/xamppfiles/htdocs/testsite中/
但这毫无意义。
/swift.php
是一个绝对路径,与您正在查找的文件夹无关
如果需要相对路径,请取出/
:
require_once("/swift.php");
错误消息显示:
警告:require_once(/swift.php):无法打开流:没有这样的文件或目录
你声称:
我相信这个错误告诉我该文件不存在,但它确实存在,我可以毫无问题地浏览它
你所谓的证据是:
我的HTML文件和“swift.php”文件本身都位于/Applications/XAMPP/xamppfiles/htdocs/testsite中/
但这毫无意义。
/swift.php
是一个绝对路径,与您正在查找的文件夹无关
如果需要相对路径,请取出/
:
require_once("/swift.php");
错误消息显示:
警告:require_once(/swift.php):无法打开流:没有这样的文件或目录
你声称:
我相信这个错误告诉我该文件不存在,但它确实存在,我可以毫无问题地浏览它
你所谓的证据是:
我的HTML文件和“swift.php”文件本身都位于/Applications/XAMPP/xamppfiles/htdocs/testsite中/
但这毫无意义。
/swift.php
是一个绝对路径,与您正在查找的文件夹无关
如果需要相对路径,请取出/
:
require_once("/swift.php");
错误消息显示:
警告:require_once(/swift.php):无法打开流:没有这样的文件或目录
你声称:
我相信这个错误告诉我该文件不存在,但它确实存在,我可以毫无问题地浏览它
你所谓的证据是:
我的HTML文件和“swift.php”文件本身都位于/Applications/XAMPP/xamppfiles/htdocs/testsite中/
但这毫无意义。
/swift.php
是一个绝对路径,与您正在查找的文件夹无关
如果需要相对路径,请取出/
:
require_once("/swift.php");
总结一下:
/Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/swift.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php
在sendmessage.php的第10行:
require_once(dirname(__FILE__)."/swift.php");
require_once(dirname(__FILE__)."/swift.php");
在swift.php的第20行:
require(dirname(__FILE__)."/classes/Swift.php");
require(dirname(__FILE__)."/classes/Swift.php");
总结一下:
/Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/swift.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php
在sendmessage.php的第10行:
require_once(dirname(__FILE__)."/swift.php");
require_once(dirname(__FILE__)."/swift.php");
在swift.php的第20行:
require(dirname(__FILE__)."/classes/Swift.php");
require(dirname(__FILE__)."/classes/Swift.php");
总结一下:
/Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/swift.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php
在sendmessage.php的第10行:
require_once(dirname(__FILE__)."/swift.php");
require_once(dirname(__FILE__)."/swift.php");
在swift.php的第20行:
require(dirname(__FILE__)."/classes/Swift.php");
require(dirname(__FILE__)."/classes/Swift.php");
总结一下:
/Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/swift.php
/Applications/XAMPP/xamppfiles/htdocs/testsite/classes/Swift.php
在sendmessage.php的第10行:
require_once(dirname(__FILE__)."/swift.php");
require_once(dirname(__FILE__)."/swift.php");
在swift.php的第20行:
require(dirname(__FILE__)."/classes/Swift.php");
require(dirname(__FILE__)."/classes/Swift.php");
这两个文件在您的项目目录中的位置是什么?我确实在顶部指出了这一点,但是完整路径是/Applications/XAMPP/xamppfiles/htdocs/testsite/Beforerequire\u once
runecho getcwd()
只是验证脚本实际运行在哪个目录中。然后尝试包含/require_一次相对于该目录的文件。这两个文件都位于项目目录中的何处?我确实在顶部附近声明了,但是在require_一次运行之前,完整路径是/Applications/XAMPP/xamppfiles/htdocs/testsite/<代码>echo getcwd()
只是验证脚本实际运行在哪个目录中。然后尝试包含/require_一次相对于该目录的文件。这两个文件都位于项目目录中的何处?我确实在顶部附近声明了,但是在require_一次运行之前,完整路径是/Applications/XAMPP/xamppfiles/htdocs/testsite/echo getcwd();
只是为了验证脚本实际运行在哪个目录中。然后尝试包含/require_一次相对于该目录的文件。Wher