{"id":395,"date":"2021-11-17T10:20:49","date_gmt":"2021-11-17T03:20:49","guid":{"rendered":"https:\/\/dani.work\/blog\/?p=395"},"modified":"2022-09-19T23:47:47","modified_gmt":"2022-09-19T16:47:47","slug":"laravel-send-email-without-mailable","status":"publish","type":"post","link":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/","title":{"rendered":"Laravel send email without Mailable"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Sometimes I forget how to send email in laravel without having to create a <code>Mailable<\/code>, and every time I get that problem, I always do a search on the internet, it&#8217;s quite often. finally after I created this blog and one of its functions is to document problems when I work. so I made this article because maybe you guys also have the same problem as me.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to do that ?<\/h2>\n\n\n\n<p>Here&#8217;s how to send email in laravel without creating &#8216;<code>Mailable<\/code>&#8216; first.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Send Raw Message (Plain Text)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\n$email   = 'destination@mail.com';\n$subject = 'This is the subject of the email;\n\nMail::raw('Hello, welcome to Laravel!', function ($message) use($email, $subject) {\n  $message-&gt;to($email)-&gt;subject($subject);\n});<\/code><\/pre>\n\n\n\n<p>Refferance : <a href=\"https:\/\/github.com\/illuminate\/mail\/blob\/v9.24.0\/Mailer.php#L205\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/github.com\/illuminate\/mail\/blob\/v9.24.0\/Mailer.php#L205<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Send Plain Text Message with variable in body<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\n$email   = 'destination@mail.com';\n$subject = 'This is the subject of the email';\n\nMail::plain('Hello {{ $name }}, welcome to Laravel!', ['name' =&gt; 'Dani'] function ($message) use($email, $subject) {\n  $message-&gt;to($email)-&gt;subject($subject);\n});<\/code><\/pre>\n\n\n\n<p>Refferance : <a href=\"https:\/\/github.com\/illuminate\/mail\/blob\/v9.24.0\/Mailer.php#L218\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/github.com\/illuminate\/mail\/blob\/v9.24.0\/Mailer.php#L218<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Send Message with Blade Template<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php line-numbers\">&lt;?php\n\n\/\/Send email with data and template from 'resource\/views'\n\n\n$email   = 'destination@mail.com';\n$subject = 'This is the subject of the email';\n\n$data = [\n    \"name\" =&gt; \"Dani\"\n];\n\nMail::send('template.email', $data, function ($message) use($email, $subject) {\n  $message-&gt;to($email)-&gt;subject($subject);\n});<\/code><\/pre>\n\n\n\n<p>Refference : <a href=\"https:\/\/github.com\/illuminate\/mail\/blob\/v9.24.0\/Mailer.php#L250\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">https:\/\/github.com\/illuminate\/mail\/blob\/v9.24.0\/Mailer.php#L250<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclution<\/h2>\n\n\n\n<p>Those are some ways to send email in Laravel without having to create a Mailable, you can use it directly in the controller or in Tinker.<\/p>\n\n\n\n<p>To get more knowledge, you can learn it directly from the source code on github or the laravel documentation<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes I forget how to send email in laravel without having to create a Mailable, and every time I get that problem, I always do a search on the internet, it&#8217;s quite often. finally after I created this blog and one of its functions is to document problems when I work. so I made this article because maybe you guys also have the same problem as me.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,28,4],"tags":[30,29,128],"class_list":["post-395","post","type-post","status-publish","format-standard","hentry","category-framework","category-laravel","category-php","tag-framework","tag-laravel","tag-mail"],"blocksy_meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Laravel send email without Mailable - Inside of Code<\/title>\n<meta name=\"description\" content=\"This code for send email without mailable classes, you can using it for simple stuff but wan&#039;t great results\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Laravel send email without Mailable - Inside of Code\" \/>\n<meta property=\"og:description\" content=\"This code for send email without mailable classes, you can using it for simple stuff but wan&#039;t great results\" \/>\n<meta property=\"og:url\" content=\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\" \/>\n<meta property=\"og:site_name\" content=\"Inside of Code\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-17T03:20:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-19T16:47:47+00:00\" \/>\n<meta name=\"author\" content=\"Dani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\"},\"author\":{\"name\":\"Dani\",\"@id\":\"https:\/\/insideofcode.com\/blog\/#\/schema\/person\/1c6cafc6659067aa7ac1fd1a5ced218d\"},\"headline\":\"Laravel send email without Mailable\",\"datePublished\":\"2021-11-17T03:20:49+00:00\",\"dateModified\":\"2022-09-19T16:47:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\"},\"wordCount\":185,\"publisher\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/#organization\"},\"keywords\":[\"Framework\",\"Laravel\",\"mail\"],\"articleSection\":[\"Framework\",\"Laravel\",\"PHP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\",\"url\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\",\"name\":\"Laravel send email without Mailable - Inside of Code\",\"isPartOf\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/#website\"},\"datePublished\":\"2021-11-17T03:20:49+00:00\",\"dateModified\":\"2022-09-19T16:47:47+00:00\",\"description\":\"This code for send email without mailable classes, you can using it for simple stuff but wan't great results\",\"breadcrumb\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/insideofcode.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Laravel send email without Mailable\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/insideofcode.com\/blog\/#website\",\"url\":\"https:\/\/insideofcode.com\/blog\/\",\"name\":\"Inside of Code\",\"description\":\"A software engineer who wants to share what he has learned, and document his journey.\",\"publisher\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/insideofcode.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/insideofcode.com\/blog\/#organization\",\"name\":\"Inside of Code\",\"url\":\"https:\/\/insideofcode.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/insideofcode.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/insideofcode.com\/wp-content\/uploads\/2022\/10\/logo-ioc.png\",\"contentUrl\":\"https:\/\/insideofcode.com\/wp-content\/uploads\/2022\/10\/logo-ioc.png\",\"width\":324,\"height\":324,\"caption\":\"Inside of Code\"},\"image\":{\"@id\":\"https:\/\/insideofcode.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/insideofcode.com\/blog\/#\/schema\/person\/1c6cafc6659067aa7ac1fd1a5ced218d\",\"name\":\"Dani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/insideofcode.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a4b1e4251720747aef0418e09fe0f6e7786ff89358b57f76822f1c52c286552b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a4b1e4251720747aef0418e09fe0f6e7786ff89358b57f76822f1c52c286552b?s=96&d=mm&r=g\",\"caption\":\"Dani\"},\"sameAs\":[\"https:\/\/insideofcode.com\/blog\"],\"url\":\"https:\/\/insideofcode.com\/blog\/author\/daniwork\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Laravel send email without Mailable - Inside of Code","description":"This code for send email without mailable classes, you can using it for simple stuff but wan't great results","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/","og_locale":"en_US","og_type":"article","og_title":"Laravel send email without Mailable - Inside of Code","og_description":"This code for send email without mailable classes, you can using it for simple stuff but wan't great results","og_url":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/","og_site_name":"Inside of Code","article_published_time":"2021-11-17T03:20:49+00:00","article_modified_time":"2022-09-19T16:47:47+00:00","author":"Dani","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Dani","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/#article","isPartOf":{"@id":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/"},"author":{"name":"Dani","@id":"https:\/\/insideofcode.com\/blog\/#\/schema\/person\/1c6cafc6659067aa7ac1fd1a5ced218d"},"headline":"Laravel send email without Mailable","datePublished":"2021-11-17T03:20:49+00:00","dateModified":"2022-09-19T16:47:47+00:00","mainEntityOfPage":{"@id":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/"},"wordCount":185,"publisher":{"@id":"https:\/\/insideofcode.com\/blog\/#organization"},"keywords":["Framework","Laravel","mail"],"articleSection":["Framework","Laravel","PHP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/","url":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/","name":"Laravel send email without Mailable - Inside of Code","isPartOf":{"@id":"https:\/\/insideofcode.com\/blog\/#website"},"datePublished":"2021-11-17T03:20:49+00:00","dateModified":"2022-09-19T16:47:47+00:00","description":"This code for send email without mailable classes, you can using it for simple stuff but wan't great results","breadcrumb":{"@id":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/insideofcode.com\/blog\/laravel-send-email-without-mailable\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/insideofcode.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Laravel send email without Mailable"}]},{"@type":"WebSite","@id":"https:\/\/insideofcode.com\/blog\/#website","url":"https:\/\/insideofcode.com\/blog\/","name":"Inside of Code","description":"A software engineer who wants to share what he has learned, and document his journey.","publisher":{"@id":"https:\/\/insideofcode.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/insideofcode.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/insideofcode.com\/blog\/#organization","name":"Inside of Code","url":"https:\/\/insideofcode.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/insideofcode.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/insideofcode.com\/wp-content\/uploads\/2022\/10\/logo-ioc.png","contentUrl":"https:\/\/insideofcode.com\/wp-content\/uploads\/2022\/10\/logo-ioc.png","width":324,"height":324,"caption":"Inside of Code"},"image":{"@id":"https:\/\/insideofcode.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/insideofcode.com\/blog\/#\/schema\/person\/1c6cafc6659067aa7ac1fd1a5ced218d","name":"Dani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/insideofcode.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a4b1e4251720747aef0418e09fe0f6e7786ff89358b57f76822f1c52c286552b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a4b1e4251720747aef0418e09fe0f6e7786ff89358b57f76822f1c52c286552b?s=96&d=mm&r=g","caption":"Dani"},"sameAs":["https:\/\/insideofcode.com\/blog"],"url":"https:\/\/insideofcode.com\/blog\/author\/daniwork\/"}]}},"_links":{"self":[{"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/posts\/395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/comments?post=395"}],"version-history":[{"count":0,"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/posts\/395\/revisions"}],"wp:attachment":[{"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/media?parent=395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/categories?post=395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/insideofcode.com\/blog\/wp-json\/wp\/v2\/tags?post=395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}