Kohana 中的 SwiftMailer 电子邮件触发数组到字符串的转换
我正在尝试使用 SwiftMailer 在 Kohana 中发送电子邮件,但不断遇到有关数组到字符串转换的错误。
我的代码是这样的:
$mailer = Email::connect();
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Hey, say hello!';
$body = 'Hello World!';
$message_swift = Swift_Message::newInstance($subject, $body)
->setFrom($from)
->setTo($to);
if ($mailer->send($message_swift))
{
echo 'Massage Send! Bravo!';
}
else
{
echo 'Message failed! Booo!';
}
显示的错误:
MODPATH/kohana-email/vendor/swift/classes/Swift/Transport/MailTransport.php [ 183 ] 错误:ErrorException [注意]:数组到字符串的转换
它所引用的 SwiftMailer 部分在这里:
178 $headers = str_replace("\r\n.", "\r\n..", $headers);
179 $body = str_replace("\r\n.", "\r\n..", $body);
180 }
181
182 if ($this->_invoker->mail($to, $subject, $body, $headers,
183 sprintf($this->_extraParams, $reversePath)))
184 {
185 if ($evt)
186 {
187 $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
188 $evt->setFailedRecipients($failedRecipients);
为什么我会收到此变量转换错误?
I'm trying to email in Kohana using SwiftMailer but keep coming across an error about an array to string conversion.
My code is thus:
$mailer = Email::connect();
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Hey, say hello!';
$body = 'Hello World!';
$message_swift = Swift_Message::newInstance($subject, $body)
->setFrom($from)
->setTo($to);
if ($mailer->send($message_swift))
{
echo 'Massage Send! Bravo!';
}
else
{
echo 'Message failed! Booo!';
}
The error displayed:
MODPATH/kohana-email/vendor/swift/classes/Swift/Transport/MailTransport.php [ 183 ]
Error: ErrorException [ Notice ]: Array to string conversion
The part of SwiftMailer it's referring to is here:
178 $headers = str_replace("\r\n.", "\r\n..", $headers);
179 $body = str_replace("\r\n.", "\r\n..", $body);
180 }
181
182 if ($this->_invoker->mail($to, $subject, $body, $headers,
183 sprintf($this->_extraParams, $reversePath)))
184 {
185 if ($evt)
186 {
187 $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
188 $evt->setFailedRecipients($failedRecipients);
Why am I getting this variable conversion error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要确保在配置文件夹中名为 email.php 的配置文件中将驱动程序设置为正确的值。
You need to make sure the driver is set to the right value in the config file called email.php found in the config folder.
$to
应该是一个数组:或者
你也可以这样做:
setFrom
也是如此。$to
should be an array:or just
you could do:
Same thing goes with
setFrom
.