laravel send email

 After a period of use, found that many places in the project need to use user authentication, SMS authentication and verification mailbox mainstream trend, wheat summarizes the functions are implemented in the Laravel framework to send mail, the future will continue on how to achieve more SMS verification.....  

      

      

In .env file

 1. Laravel configuration file

     MAIL_DRIVER = smtp // recommended way smtp

     MAIL_HOST = smtp.163.com // recommended to use QQ mailbox 163 mailboxes have an error

     MAIL_PORT = 25 // smtp default is 25   

     MAIL_USERNAME = null // own account 163

     MAIL_PASSWORD = null // client password

     MAIL_ENCRYPTION=null

.

2. Modify the config / email.php file 

            'From' => [ 'address' => null, 'name' => null], it did not prompt the // manual, but the practical application if addredd => null the error, need 163 days to write their address

 

3. 163 registered mail and email account settings POP3 / SMTP / IMAP should be open and turn on the authorization code and phone verification

        

 

4. Laravel reference manual mailing

                It must be noted that reference must first use Mail message is sent when the controller reference

    Send a test message

    Set in the routing 

      

    Writing method in the controller

                

    Among

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​1:Mail::raw  是发送原生数据,其他的内容发送方式在手册里都有提供;

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​2.$message->subjuet('');是文件的标题

    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​3.$message->to();发送给谁

    ​    ​    ​

这是一份在 $message 消息生成器实例中可以使用的方法清单:

$message->from($address, $name = null); $message->sender($address, $name = null); $message->to($address, $name = null); $message->cc($address, $name = null);//抄送 $message->bcc($address, $name = null); $message->replyTo($address, $name = null); $message->subject($subject); $message->priority($level); $message->attach($pathToFile, array $options = []);  // 以原始 $data 字符串附加一个文件... $message->attachData($data, $name, array $options = []);  // 获取底层的 SwiftMailer 消息实例... $message->getSwiftMessage();
public function send(){ 
    $image = Storage::get('images/obama.jpg'); //本地文件
    //$image = 'http://www.baidu.com/sousuo/pic/sdaadar24545ssqq22.jpg';//网上图片
    Mail::send('emails.test',['image'=>$image],function($message){ 
        $to = '[email protected]';
        $message->to($to)->subject('图片测试'); 
    }); 
    if(count(Mail::failures()) < 1){
     echo '发送邮件成功,请查收!'; 
    }else{
     echo '发送邮件失败,请重试!';
    } 
}

Guess you like

Origin www.cnblogs.com/hanmengya/p/10931892.html