【问题标题】:When i am trying to send mail from contactUS form getting this error using swiftmailer in Laravel 5.2当我尝试使用 Laravel 5.2 中的 swiftmailer 从 contactUS 表单发送邮件时收到此错误
【发布时间】:2016-05-05 11:21:03
【问题描述】:

当我尝试通过“联系我们”表单发送邮件时收到此错误

“给定 [] 邮箱中的地址不符合 RFC 2822, 3.6.2。” 我尝试搜索以找到解决方案,但找不到。我编辑了 config/mail.php

public function sendContactInfo(ContactMeRequest $request)
{
    $data = $request->only('name', 'email');
    $emailto="******@gmail.com";
    $data['messageLines'] = explode("\n", $request->get('message'));
    Mail::send('publicPages.contactus', $data, function ($message) use ($emailto) {

        $message->subject('Contact Us Form: ')
            ->to(config('blog.contact_email'))
            ->replyTo($data['email']);
    });

    return back()
        ->withSuccess("Thank you for your message. It has been sent.");
}

带配置文件

我正在关注本教程 Laravel Send Mail

【问题讨论】:

  • 你的php版本是什么
  • 你试过PHPMailer,它是我找到的最好的图书馆

标签: laravel gmail swiftmailer


【解决方案1】:

使用 $data['email']

   Mail::send('publicPages.contactus', $data, function ($message) use ($emailto,$data['email']) {

        $message->subject('Contact Us Form: ')
            ->to(config('blog.contact_email'))
            ->replyTo($data['email']);
    });

【讨论】:

  • 我之前正在使用 $data['email'] 但错误是一样的.. 这就是为什么我将电子邮件存储在一个单独的变量中并使用 $emailto 只是为了确保电子邮件正确传递
  • 检查 mail.php.in 中的 'from' => ['address' =>null, 'name' =>null],不能为空。为 from 和 name 赋值
  • 错误来自这些代码行 codeprivate function _assertValidAddress($address) { if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr -spec').'$/D', $address)) { throw new Swift_RfcComplianceException('给定邮箱中的地址 ['.$address.'] 不符合 RFC 2822, 3.6.2.'); } }
  • Boora 我已经尝试过了,同时评论说功能应用功能停止工作可能是错误来了,因为 em 在 Config/mail.php 文件中使用硬编码值 'from' => ['address' => '********@gmail.com', 'name' => 'Wajahat Hashmi'], 但是当我从 .env 引用值得到相同的错误
猜你喜欢
  • 1970-01-01
  • 2017-04-26
  • 1970-01-01
  • 2021-06-17
  • 2015-05-05
  • 2015-03-20
  • 2020-06-02
  • 2022-01-24
  • 2011-04-28
相关资源
最近更新 更多