【发布时间】:2017-02-17 03:45:44
【问题描述】:
我正在实施一个邮件解决方案,如果我从主 index.php 文件中调用 swiftmailer,例如:
require_once '../swiftmailer/lib/swift_required.php';
...
$result = $mailer->send($message);
一切都很好。但是当我在我的应用程序类中使用相同的 swiftmailer 库来实现这样的布局/设计分区时:
// File: controller.php
class Index {
...
public function ignition() {
...
spl_autoload_register(array($this, 'myClassLoaderFx'));
}
public function myClassLoaderFx($name) {
$classes = array(
'Blah' => '../blah/Blah.php',
...
'Swift' => '../swiftmailer/lib/swift_required.php'
);
if(!array_key_exists($name, $classes)){
die('Class not found');
}
require_once $classes[$name];
}
// File: Mailer.php
class Mailer {
...
public function main($recepient[], $sender, $subject, $body) {
...
$transport = Swift_SmtpTransport::newInstance('xyz.google.com', 465, "ssl")->setUsername($this->username)->setPassword($this->password);
...
$result = $mailer->send($message);
}
执行后我得到:找不到类“Swift_SmtpTransport”。该库已加载,因为我在 netbeans 上下文帮助中获得了所有 Swift 类列表。但是,在执行时我得到了错误。我已经完成了所有可能的拼写检查。从此无处可去。请帮忙。
【问题讨论】:
-
这里的答案:stackoverflow.com/questions/29626658/… used "Swift_SmtpTransport::newyInstance()" 如果 y 是拼写错误,或者您需要 y 才能正常工作,我不确定。跨度>
-
我检查了拼写错误,还检查了函数名称。没有到达任何地方。谢谢。
标签: php swiftmailer spl-autoload-register