PHP Swift邮件程序设置

PHP Swift邮件程序设置,php,html,email,smtp,swiftmailer,Php,Html,Email,Smtp,Swiftmailer,我正在尝试在我的网站上安装swift mailer,这样我就可以向注册用户发送密码恢复电子邮件。我用的是dreamweaver。我所做的: 1) Downloaded Swift-4.2.2.tar 2) Extracted it 3) Uploaded to my host in /Domain/classes/lib 4) Included it in Recovery.php 这是我的文件结构 Main Folder |classes |Swift

我正在尝试在我的网站上安装swift mailer,这样我就可以向注册用户发送密码恢复电子邮件。我用的是dreamweaver。我所做的:

1) Downloaded Swift-4.2.2.tar
2) Extracted it
3) Uploaded to my host in /Domain/classes/lib
4) Included it in Recovery.php
这是我的文件结构

Main Folder
     |classes
          |Swift
     |Private
          |Recovery.php
下面是
Recovery.php

require_once '../classes/lib/swift_required.php';
// Create the Transport
$email_to = $_POST["email"];
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465)
  ->setUsername('Username')
  ->setPassword('Password')
  ;

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance()

  // Give the message a subject
  ->setSubject('Password Recovery')

  // Set the From address with an associative array
  ->setFrom(array('Username@domain.com' => 'Username'))

  // Set the To addresses with an associative array
  ->setTo($email_to)

  // Give it a body
  ->setBody('Below is your temporary password. Please make sure to login in immediately and change it to a password of your choice.\n'.$password);

// Send the message
$result = $mailer->send($message);
但这不包括库,因为如果我执行
Swift\u SmtpTransport::
,那么dreamweaver应该会弹出一个intellisense东西,为我提供方法或变量选项,这意味着它可以查看类及其所有成员项。但是由于它没有弹出选项,我感觉它看不到swift类是什么。当我尝试运行它时,console network选项卡说它挂起了一段时间,然后返回了
500内部服务器错误
。所以它没有正确地包含库。知道我做错了什么吗

编辑: 错误报告输出:

Warning: require(/*/*/*/Main Folder/classes/lib/classes/Swift.php): failed to open stream: No such file or directory in /*/*/*/Main Folder/classes/lib/swift_required.php on line 22 
Fatal error: require(): Failed opening required '/*/*/*/Main Folder/classes/lib/classes/Swift.php' (include_path='.:/usr/local/lib/php') in /*/*/*/Main Folder/classes/lib/swift_required.php on line 22

当您检查swift_required.php中的路径时,可能会有所帮助,从调用文件的角度来看,这些路径必须是正确的

打开swift_required.php文件。第22行有一个require()。调整其路径以匹配lib/classes/Swift.php

尝试使用绝对路径而不是相对路径

例如在linux中

require_once '/var/www/project/mailer/lib/swift_required.php' ;
或者,尝试将上述行替换为

require_once '/path/to/mailer/lib/swift_init.php';

swift mailer使用自己的类自动加载器,您是否已经有其他自动加载器?

是否启用了错误报告功能?如果出现500个错误,error.log会说什么?顺便说一句,IDE行为与此无关。@mario我没有启用错误报告。但是我认为这不会有什么帮助,因为
Recovery.php
是在主页上使用ajax调用的。如何显示任何错误报告输出?直接访问
Recovery.php
。您是否更改了
swift\u required.php
文件位置?@freon no根本没有。我只是从rar复制了lib文件夹,并将其粘贴到我的classes文件夹中。无更改
swift\u required.php的第22行读取
require dirname(\uu文件)/class/Swift.php'。您希望我如何更改它?
require./classes/Swift.php'仍然收到错误。现在我有了这个错误:
Warning:require(./classes/Swift.php):打开流失败:在第22行的/*/*/*/*/Main Folder/classes/lib/Swift_required.php中没有这样的文件或目录致命错误:require():无法打开required./classes/Swift.php'(include_path=':/usr/local/lib/php')在/*/*/*/Main Folder/classes/lib/swift_required.php的第22行
nvm中,它现在没有明显的原因工作了。我真的把它恢复到以前的版本,它开始工作了。谢谢