dpwtr666638 2018-11-07 03:38
浏览 251

无法使用获取请求电子邮件地址变量在Mail :: raw中发送电子邮件

Herewith I'm using 'Mail::raw()' to send and email in Laravel - PHP. After getting request from the database, I assigned the receiver's email address to '$email'. In this case '$message->to('$email');' given an error 'Address in mailbox given [$email] does not comply with RFC 2822, 3.6.2.'. Instead of '$email', 'abcdef@test.com' its working perfectly. And also inside the 'Mail::row()' function, unable to get request values instead of hard code email address. Below is the code.

Controller.php

public function sendEmailToUser(Request $request)
    {
    $email = (String)$request->get('email');
    $messageBody = $request->get('password');

    $response = null;
    $res_type = null;

    \Mail::raw($messageBody, function ($message) {
        $message->from('abcd@gmail.com', 'TESTING');
        $message->to('$email');
        $message->subject('TESTING TITLE');
    });

    // check for failures
    if (\Mail::failures()) 
    {
        $response ="Email sent unsuccess";
        $res_type = 'warning';
    }
    else
    {
        $response ="Email sent successful";
        $res_type = 'success';

    }

    return redirect()->back()->with($response,$res_type);
}
  • 写回答

1条回答 默认 最新

  • doubeizhong5178 2018-11-07 05:42
    关注

    Finally got a solution is use '$request' with \Mail::row() function.

    \Mail::raw($request->password, function ($message) use($request) 
            {
                $message->from($request->fromEmail, 'TESTING');
                $message->to($request->toEmail);
                $message->subject('TESTING TITLE');
            });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法