laravelを使って、お問い合わせフォームを作成しています。
フォームに入力頂いたデータをDBに保存して、
入力頂いた相手と、運営者側に自動でメールが届くようになりました。
その後、エラーに対する処理をしていたところ、
フォームに入力いただいた、メールアドレスが存在しないときにエラーが出ます。
エラーが出たときにtyr catchなどで、エラーをキャッチして別の処理をしたいのですが、
エラーを捕まえることが出来ません。
1日、調べていたのですが、どこから調べていいのかわからなくなってしまいしました。
お忙しい中、恐縮なのですが、ご教授いただけましたら幸いです。
よろしくお願いいたします。
発生している問題・エラーメッセージ
Swift_TransportException (553) Expected response code 250 but got code "553", with message "553 5.1.8 <asdfasd@asdfas.ads>... Domain of sender address asdfasd@asdfas.ads does not exist "
該当のソースコード
laravel
1 public function complete(ContactRequest $request){ 2 $input = $request->except('action'); 3 4 if($request->action == '戻る'){ 5 return redirect()->action('ContactController@index')->withInput($input); 6 } 7 8 if(isset($request->type)){ 9 $request->merge(['type' => implode(',',$request->type)]); 10 } 11 12 Contact::create($request->all()); 13 14 $request->session()->regenerateToken(); 15 16 // 送信メール 17 \Mail::send(new \App\Mail\Contact([ 18 'to' => $request->email, 19 'to_name' => $request->name, 20 'from' => 'info@etc.jp', 21 'from_name' => '名前', 22 'subject' => 'お問い合わせありがとうございました。', 23 'type' => $request->type, 24 'tel' => $request->tel, 25 'body' => $request->body 26 ])); 27 28 // 受信メール 29 \Mail::send(new \App\Mail\Contact([ 30 'to' => 'info@etc.jp', 31 'to_name' => 'MySite', 32 'from' => $request->email, 33 'from_name' => $request->name, 34 'subject' => 'サイトからのお問い合わせ', 35 'type' => $request->type, 36 'tel' => $request->tel, 37 'body' => $request->body 38 ], 'from')); 39 40 41 return view('contact.complete'); 42 43 }
試したこと
メールを送信するときにエラーが発生していると思い、
Mail::sendのところで、try catchなどしてもすべて通り抜けてしまいます。
try{
// 送信メール
\Mail::send(new \App\Mail\Contact([
'to' => $request->email,
'to_name' => $request->name,
'from' => 'info@ets.jp',
'from_name' => 'gnamgnam',
'subject' => 'お問い合わせありがとうございました。',
'type' => $request->type,
'tel' => $request->tel,
'body' => $request->body
]));
}catch (\Swift_TransportException $STe) {
return view('contact.complete');
}catch(\Exception $e){
return view('contact.complete');
}
補足情報(FW/ツールのバージョンなど)
環境は下記です。
Laravel Framework 5.8.28
XAMPP 7.2.14
お手数をおかけいたしますが、よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/05 14:24