Kohana 中的 SwiftMailer 电子邮件触发数组到字符串的转换

发布于 2024-12-05 02:13:23 字数 1405 浏览 6 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔嚣张 2024-12-12 02:13:23

您需要确保在配置文件夹中名为 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.

清引 2024-12-12 02:13:23

$to 应该是一个数组:

$to = array($email => $name);

或者

$to = array($email);

你也可以这样做:

$message_swift = Swift_Message::newInstance($subject, $body)
->setFrom(array($from))
->setTo(array($to));

setFrom 也是如此。

$to should be an array:

$to = array($email => $name);

or just

$to = array($email);

you could do:

$message_swift = Swift_Message::newInstance($subject, $body)
->setFrom(array($from))
->setTo(array($to));

Same thing goes with setFrom.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文