{"id":129,"date":"2022-11-03T09:33:49","date_gmt":"2022-11-03T00:33:49","guid":{"rendered":"https:\/\/global-hack.com\/blog\/?p=129"},"modified":"2022-11-08T08:45:23","modified_gmt":"2022-11-07T23:45:23","slug":"%e3%80%90laravel%e3%80%91view%e3%82%92%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%aa%e3%81%84%e7%b0%a1%e6%98%93%e7%9a%84%e3%81%aa%e3%83%a1%e3%83%bc%e3%83%ab%e3%81%ae%e9%80%81%e4%bf%a1%e6%96%b9%e6%b3%95%e3%80%90","status":"publish","type":"post","link":"https:\/\/global-hack.com\/blog\/archives\/129","title":{"rendered":"\u3010Laravel\u3011view\u3092\u6307\u5b9a\u3057\u306a\u3044\u7c21\u6613\u7684\u306a\u30e1\u30fc\u30eb\u306e\u9001\u4fe1\u65b9\u6cd5\u3010Mail::raw\u3011"},"content":{"rendered":"<h3>Laravel\u306e\u57fa\u672c\u7684\u306a\u30e1\u30fc\u30eb\u9001\u4fe1\u65b9\u6cd5<\/h3>\n<p>\u3053\u3053\u3067\u306fLaravel9\u3067\u306e\u8a66\u307f\u3067\u3042\u3063\u305f\u305f\u3081\u3001Laravel8\u4ee5\u524d\u3067\u4f7f\u7528\u3057\u3066\u304d\u305fSwift Mailer\u304b\u3089\u3001Laravel9\u4ee5\u964d\u3067\u7528\u3044\u308b<a href=\"https:\/\/readouble.com\/laravel\/9.x\/ja\/mail.html\" target=\"_blank\" rel=\"nofollow noopener\" title=\"Laravel 9.x \u30e1\u30fc\u30eb Symfony Mailer \u306b\u3064\u3044\u3066\">Symfony Mailer<\/a>\u3092\u5c0e\u5165\u3057\u3066\u304b\u3089\u884c\u3044\u307e\u3059\u3002\u6700\u521d\u304b\u3089Laravel9\u3067\u59cb\u3081\u308b\u65b9\u306f\u3001\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u306b\u3064\u3044\u3066\u306f\u98db\u3070\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u5165\u308c\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>$ composer require symfony\/mailgun-mailer symfony\/http-client\r\n<\/code><\/pre>\n<\/div>\n<p><!--more--><\/p>\n<p>\u307e\u305a\u306f\u3001\u3088\u304f\u3042\u308b\u7c21\u6613\u9001\u4fe1\u65b9\u6cd5\u304c\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3069\u3053\u306b\u3067\u3082\u3042\u308b\u3001\u3088\u304f\u7d39\u4ecb\u3055\u308c\u308b\u3088\u3046\u306a\u4f8b\u3067\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Illuminate\\Http\\Request;\r\nuse Illuminate\\Support\\Facades\\Mail;\r\n\r\nclass SendMailController extends Controller\r\n{\r\n    public static function exampleSendMail($data = \"\")\r\n    {\r\n        Mail::raw($data, function ($message) {\r\n            $message-&gt;to('mail@example.com')-&gt;subject('\u3053\u3053\u306b\u30e1\u30fc\u30eb\u30bf\u30a4\u30c8\u30eb');\r\n        });\r\n        return;\r\n    }\r\n}<\/code><\/pre>\n<\/div>\n<p>\u5192\u982d\u4ed8\u8fd1\u306e\u300cuse Illuminate\\Support\\Facades\\Mail;\u300d\u3067Laravel\u304c\u5099\u3048\u3066\u3044\u308b<span>\u30d5\u30a1\u30b5\u30fc\u30c9<\/span>\u3092\u547c\u3073\u51fa\u3057\u3001view\u3092\u4f7f\u7528\u3057\u306a\u3044\u7c21\u6613\u7684\u306a\u30e1\u30fc\u30eb\u9001\u4fe1\u306e\u30e1\u30bd\u30c3\u30c9\u300cMail::raw\u300d\u3092\u7528\u3044\u308b\u306e\u304c\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002\u3061\u306a\u307f\u306bview\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u300cMail::send\u300d\u3092\u7528\u3044\u3066\u5f15\u6570\u306bview\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u306f\u672c\u5f53\u306b\u3088\u304f\u3042\u308b\u300c\u3044\u304b\u304b\u304c\u3067\u3057\u305f\u3067\u3057\u3087\u3046\u304b\uff01\uff1f\u300d\u7684\u306a\u6280\u8853\u30d6\u30ed\u30b0\u3067\u3088\u304f\u898b\u308b\u3084\u3064\u3067\u3059\uff08\u7b11\uff09<\/p>\n<h3>Mail::raw\u306e\u30e1\u30fc\u30eb\u30bf\u30a4\u30c8\u30eb\u3084\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u5909\u6570\u3067\u64cd\u308b<\/h3>\n<p>\u3053\u3053\u304b\u3089\u306f\u4e2d\u3005\u691c\u7d22\u306b\u898b\u3064\u304b\u3089\u305a\u306b\u3001\u4ee5\u524d\u4f55\u4eba\u304b\u306b\u5b9f\u969b\u306b\u8cea\u554f\u3055\u308c\u305f\u5185\u5bb9\u306e\u7b54\u3048\u3092\u3056\u3063\u304f\u308a\u3068\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u5148\u307b\u3069\u306e\u300c<code>'mail@example.com'<\/code>\u300d\u3084\u300c<code>'\u3053\u3053\u306b\u30e1\u30fc\u30eb\u30bf\u30a4\u30c8\u30eb'<\/code>\u300d\u306e\u90e8\u5206\u3092\u5909\u6570\u306b\u3057\u3066\u3001\u52d5\u7684\u306b\u5024\u304c\u30bb\u30c3\u30c8\u3055\u308c\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u3069\u3046\u3057\u305f\u3089\u3044\u3044\u306e\u304b\u3002\u305d\u306e\u307e\u307e\u5909\u6570\u306b\u3057\u3066\u3057\u307e\u3046\u3068\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u65e2\u306b\u4f5c\u6cd5\u3092\u77e5\u3063\u3066\u3044\u308b\u65b9\u306a\u3089\u3070\u76f4\u3050\u306b\u7b54\u3048\u304c\u308f\u304b\u308b\u3067\u3057\u3087\u3046\u304c\u3001\u3068\u308a\u3042\u3048\u305a\u3053\u3053\u306f\u52ff\u4f53\u3076\u3089\u305a\u306b\u4e0b\u8a18\u306b\u30b3\u30fc\u30c9\u3092\u793a\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Illuminate\\Http\\Request;\r\nuse Illuminate\\Support\\Facades\\Mail;\r\n\r\nclass SendMailController extends Controller\r\n{\r\n    public static function exampleCustomSendMail($dataArray = array()){\r\n        $res = FALSE;\r\n        if (\r\n            Mail::raw($dataArray['message_data'], function ($message) use($dataArray){\r\n                $message-&gt;to($dataArray['email'])-&gt;subject($dataArray['subject']);\r\n            })\r\n        ) {\r\n            $res = TRUE;\r\n        }\r\n        return $res;\r\n    }\r\n}<\/code><\/pre>\n<\/div>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u300c<code>use($dataArray)<\/code>\u300d\u3067\u30e1\u30bd\u30c3\u30c9\u5185\u306b\u5f15\u304d\u7d99\u3050\u3068\u3053\u308d\u3067\u3059\uff08\u203b\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u30b9\u30b3\u30fc\u30d7\u3067\u5bfe\u5fdc\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\uff09\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u4f7f\u3044\u65b9\u3068\u3057\u3066\u3001\u3053\u306e\u300c<code>exampleCustomSendMail<\/code>\u300d\u3092\u547c\u3073\u51fa\u3059\u3068\u3053\u308d\u3067\u3001\u4e8b\u524d\u306b\u4e0b\u8a18\u306e\u3088\u3046\u306b\u300c<code>$dataArray<\/code>\u300d\u306e\u5f15\u6570\u914d\u5217\u306b\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\r\n\r\nnamespace App\\Http\\Controllers;\r\n\r\nuse Illuminate\\Http\\Request;\r\nuse App\\Http\\Controllers\\SendMailController;\r\n\r\nclass ContactController extends Controller\r\n{\r\n\r\n    \/\/ \u4e00\u90e8\u7701\u7565\r\n\r\n    public function contactRequest(Request $request){\r\n        $resArray = array();\r\n\r\n        \/\/ \u4e00\u90e8\u7701\u7565\r\n\r\n        $dataArray['message_data']  = \"\u9001\u4fe1\u5185\u5bb9\uff08\u4f8b\uff1a$request-&gt;data\uff09\";\r\n        $dataArray['email']         = \"\u9001\u4fe1\u8005\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9(\u4f8b\uff1a$request-&gt;email)\";\r\n        $dataArray['subject']       = \"\u30e1\u30fc\u30eb\u30bf\u30a4\u30c8\u30eb(\u4f8b\uff1a$request-&gt;subject)\";\r\n\r\n        $res = SendMailController::exampleCustomSendMail($dataArray);\r\n        if ($res == FALSE) {\r\n            \/\/ \u9001\u4fe1\u30a8\u30e9\u30fc\u6642\r\n            $resArray['err'] = \"\u9001\u4fe1\u30a8\u30e9\u30fc\u3060\u3088\uff01\";\r\n        } else {\r\n            \/\/ \u9001\u4fe1\u6210\u529f\u6642\r\n            $resArray['res'] = \"\u9001\u4fe1\u6210\u529f\u3060\u3088\uff01\";\r\n        }\r\n        return json_encode($resArray);\r\n    }\r\n\r\n}<\/code><\/pre>\n<\/div>\n<p>\u5225\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u304b\u3089\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u969b\u306f\u4e0a\u8a18\u306e\u3088\u3046\u306b\u5192\u982d\u4ed8\u8fd1\u306b\u3066\u300c<code>use App\\Http\\Controllers\\SendMailController;<\/code>\u300d\u3068\u3057\u3066\u3001\u5b9f\u884c\u7b87\u6240\u306b\u3066\u300c<code>SendMailController::exampleCustomSendMail<\/code>\u300d\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u88dc\u8db3\u3067\u3059\u304c\u3001\u30e1\u30fc\u30eb\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u30a8\u30e9\u30fc\u30c1\u30a7\u30c3\u30af\u306e\u305f\u3081\u306bLaravel8\u4ee5\u524d\u3067\u4f7f\u3048\u305f\u300cMail::failures()\u300d\u304c\u3042\u308a\u307e\u3057\u305f\u304c\u3001Laravel9\u3067\u306f\u4f7f\u3048\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u6025\u907dif\u6587\u306e\u6761\u4ef6\u306e\u4e2d\u306b\u300c<code>Mail::raw<\/code>\u300d\u3092\u4ed5\u8fbc\u3093\u3067\u6210\u529f\u307e\u305f\u306f\u5931\u6557\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001Laravel\u306e\u7c21\u6613\u7684\u306a\u30e1\u30fc\u30eb\u9001\u4fe1\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3067\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Laravel\u306e\u57fa\u672c\u7684\u306a\u30e1\u30fc\u30eb\u9001\u4fe1\u65b9\u6cd5 \u3053\u3053\u3067\u306fLaravel9\u3067\u306e\u8a66\u307f\u3067\u3042\u3063\u305f\u305f\u3081\u3001Laravel8\u4ee5\u524d\u3067\u4f7f\u7528\u3057\u3066\u304d\u305fSwift Mailer\u304b\u3089\u3001Laravel9\u4ee5\u964d\u3067\u7528\u3044\u308bSymfony Mailer\u3092\u5c0e\u5165\u3057\u3066\u304b\u3089\u884c\u3044\u307e\u3059\u3002\u6700\u521d\u304b\u3089L <a class=\"mh-excerpt-more\" href=\"https:\/\/global-hack.com\/blog\/archives\/129\" title=\"\u3010Laravel\u3011view\u3092\u6307\u5b9a\u3057\u306a\u3044\u7c21\u6613\u7684\u306a\u30e1\u30fc\u30eb\u306e\u9001\u4fe1\u65b9\u6cd5\u3010Mail::raw\u3011\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,12],"tags":[76,77,74,75],"class_list":["post-129","post","type-post","status-publish","format-standard","has-post-thumbnail","category-laravel","category-php","tag-controller","tag-laravel9","tag-mailer","tag-subject"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/global-hack.com\/blog\/wp-content\/uploads\/2022\/11\/laravel9.png","_links":{"self":[{"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":0,"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/media\/130"}],"wp:attachment":[{"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/global-hack.com\/blog\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}