【发布时间】:2015-10-18 18:09:51
【问题描述】:
我是 Swiftmailer 的新手,正在尝试通过本地主机 (XAMPP) 上的 HTML 联系表单发送邮件。按下“提交”按钮后,错误显示为:
致命错误:在中找不到类“Swift_SmtpTransport” /Applications/XAMPP/xamppfiles/htdocs/testsite/sendmessage.php 上线 23
第 23、24 和 25 行是这个部分:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('foobar@googlemail.com')
->setPassword('GENERATED PASSWORD');
我期待邮件此时发送,并向我显示“已发送邮件”消息,以及 PHP 文件中的回显行,但是当我看到 "Mail Sent" 确认时,我也收到了错误,我没有收到电子邮件。
我查阅了文档here,我在'sendmessage.php' 中的代码似乎是正确的:
<?php
error_reporting(E_ALL);
echo getcwd();
echo function_exists('proc_open') ? "Yep, that will work" : "Sorry, that won't work";
require_once(dirname(__FILE__)."/swift.php");
echo 'Mail sent <br />';
// Grab the post data
$name = filter_var($_POST['Name'], FILTER_SANITIZE_STRING);
$usermail = filter_var($_POST['Email'], FILTER_SANITIZE_EMAIL);
$content = filter_var($_POST['Message'], FILTER_SANITIZE_STRING);
// Construct the body of the email
$data = "Name: " . $name . "<br />" . "Email: " . $usermail . "<br />" . "Message: " . $content;
// Create the transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('foobar@googlemail.com')
->setPassword('GENERATED PASSWORD');
echo 'line 26 <br />';
// Create the mailer using the created transport
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('This is the subject')
->setFrom(array('foobar@googlemail.com' => 'Feedback Received From User'))
->setTo(array('barfoo@gmail.com', 'foobar@googlemail.com' => 'Lead Recipients'))
->setSubject('Here is your Feedback subject')
->setBody($data, 'text/html');
echo 'line 34 <br />';
// Send the message
$result = $mailer -> send($message);
echo $result;
echo 'line 39<br />';
?>
proc_open 返回"Yep, that will work",但如上所述,我的收件箱中没有收到电子邮件。
我已尝试将相关线路上的端口更改为 25 和 486,但没有成功。
在 Google 搜索后,我发现 this question 似乎有同样的问题,但接受的答案并没有解决我的问题。
请注意,我收到了一个关于联系表单错误的previous question,这个问题紧随其后。
【问题讨论】:
标签: php smtp swiftmailer