使用SwiftMailer在Laravel 4中发送邮件

ule*_*Mzy 2 swiftmailer laravel laravel-4

我收到以下错误:

没有收件人,无法发送邮件

这是在尝试使用swiftmailer发送电子邮件时.我的代码在localhost中工作,并且具有从发送方到接收方所需的所有参数,但是它会抛出错误,说它无法在没有收件人的情况下发送.

这是我的代码:

public function email()
{


    Mail::send('emails.auth.mail', array('token'=>'SAMPLE'), function($message){
        $message = Swift_Message::newInstance();
        $email = $_POST['email']; $name = $_POST['name']; $subject = $_POST['subject']; $msg = $_POST['msg']; 

        $message = Swift_Message::newInstance()
            ->setFrom(array($email => $name))
            ->setTo(array('name@gmail.com' => 'Name'))           
            ->setSubject($subject)
            ->setBody($msg);




        $transport = Swift_MailTransport::newInstance('smtp.gmail.com', 465, 'ssl');
        //$transport->setLocalDomain('[127.0.0.1]');

        $mailer = Swift_Mailer::newInstance($transport);
        //Send the message
        $result = $mailer->send($message);
        if($result){

             var_dump('worked');
        }else{
            var_dump('Did not send mail');
        }
  }
Run Code Online (Sandbox Code Playgroud)

}

fid*_*per 7

您可以在不在实现中添加SMTP信息的 Mail::send()情况下执行此操作.

假设您还没有,请转到app/config/mail.php并编辑以下内容以满足您的需求:

'host' => 'smtp.gmail.com',
'port' => 465,
'encryption' => 'ssl',
'username' => 'your_username',
'password' => 'your_password',
Run Code Online (Sandbox Code Playgroud)

然后你的代码应该像下面这样简单:

public function email()
{
    Mail::send('emails.auth.mail', array('token'=>'SAMPLE'), function($message)
    {
        $message->from( Input::get('email'), Input::get('name') );

        $message->to('name@gmail.com', 'Name')->subject( Input::get('subject') );
    });
}
Run Code Online (Sandbox Code Playgroud)

所以,希望问题是配置问题.您是否有其他环境设置可能会超出app/config/mail.php服务器中无法正常工作的配置设置?