我和swiftmailer有点麻烦。它一直在我身上崩溃,但如果我取出->sentTo,它不会出错,但我也收不到电子邮件。
我对我做错了什么感到困惑。
require_once 'lib/swift_required.php';
// Using smtp
//$transport = Swift_SmtpTransport::newInstance('my_smtp_host.com', 25)
//Using Gmail
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('***') // or your gmail username
->setPassword('***'); // or your gmail password
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance($subject)
->setFrom(array($email => $name))
->setTo(array('John.Doe@gmail.com' => 'John Doe'))
->setBody($content, 'text/html');
$message->attach(
Swift_Attachment::fromPath($_FILES['userfile']['name'])->setFilename($pic['tmp_name'])
);
// Send the message
$result = $mailer->send($message);
?>致命错误:
Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "...." using 2 possible authenticators' in ../lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184
Stack trace:
0 ../lib/classes/Swift/Transport/Esmtp/EsmtpTransport.php(312): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
1 ../lib/classes/Swift/Transport/AbstractSmtpTransport.php(120): Swift_Transport_EsmtpTransport->_doHeloCommand()
2 ../lib/classes/Swift/Mailer.php(80): Swift_Transport_AbstractSmtpTransport->start()
3 upload.php(73): Swift_Mailer->send(Object(Swift_Message))
4 {main} thrown in lib/classes/Swift/Transport/Esmtp/AuthHandler.php on line 184发布于 2013-02-20 02:00:05
我必须将邮件附件更改为以下内容:
$message->attach(
Swift_Attachment::fromPath($theDirectory)->setFilename($fileNameForEmail)
);
// Send the message
$result = $mailer->send($message);
}
else{
echo 'The file you have chosen is invalid. Please go back and try again.';
}发布于 2013-02-20 02:01:47
这一点:
无法使用用户名"....“在SMTP服务器上进行身份验证。使用2种可能的身份验证器
..。就像它说的那样。Gmail不接受您的用户名和密码,可能是因为它们是错误的,也可能是因为您未能提供某些必需的参数。
根据other questions at Stack Overflow和我自己的测试,主机名、端口和加密都是正确的。因此,问题可能包括:
一旦你修复了这个问题,你可能会得到以下异常:
未捕获异常'Swift_IoException‘,并显示消息'Unable to open file for reading []’
..。由此代码触发:
Swift_Attachment::fromPath($_FILES['userfile']['name'])如果您从$_FILES array读取了错误的项,原因是:fromPath()需要读取文件系统路径,但$_FILES['userfile']['name']包含客户端计算机上文件的原始名称。
https://stackoverflow.com/questions/14963323
复制相似问题