{"id":19,"date":"2023-08-19T07:23:04","date_gmt":"2023-08-19T07:23:04","guid":{"rendered":"https:\/\/mailmug.net\/blog\/?p=19"},"modified":"2023-08-20T03:16:53","modified_gmt":"2023-08-20T03:16:53","slug":"email-php-slim-framework","status":"publish","type":"post","link":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/","title":{"rendered":"Send Email in PHP Slim Framework with Controllers"},"content":{"rendered":"\n<p>Easy-to-follow guide for sending emails from PHP Slim Framework. You can try it out using a <a href=\"https:\/\/mailmug.net\/\">fake SMTP account<\/a>.<\/p>\n\n\n\n<div style=\"height:34px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 1: Install PHPMailer library by composer from Packagist <\/strong><\/h2>\n\n\n\n<p>Go to php slim root folder by terminal then execute the following command. It will automatically install the email library from <a href=\"https:\/\/packagist.org\/packages\/phpmailer\/phpmailer\">Packagist<\/a>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncomposer require phpmailer\/phpmailer\n<\/pre><\/div>\n\n\n<div style=\"height:52px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 2: Add the Following Code  in Route\/Controller<\/strong><\/h2>\n\n\n<div class=\"wp-block-image is-style-default img-fluid\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/php-slim-framework-email.png\"><img loading=\"lazy\" decoding=\"async\" width=\"653\" height=\"352\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/php-slim-framework-email.png\" alt=\"PHP Slim Framework Email\" class=\"wp-image-39\" style=\"object-fit:cover\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/php-slim-framework-email.png 653w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/php-slim-framework-email-300x162.png 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/a><\/figure><\/div>\n\n\n<div style=\"height:47px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>You can easily test email functions with fake SMTP testing servers like <strong><a href=\"https:\/\/mailmug.net\/\">MailMug<\/a><\/strong>. Just create a free account. Then go to Inbox and copy credentials from the settings page. Then add credentials to the following code. <\/p>\n\n\n\n<div style=\"height:56px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\nuse Psr\\Http\\Message\\ResponseInterface as Response;\nuse Psr\\Http\\Message\\ServerRequestInterface as Request;\nuse Slim\\Factory\\AppFactory;\nuse PHPMailer\\PHPMailer\\PHPMailer;\n\nrequire __DIR__ . &#039;\/..\/vendor\/autoload.php&#039;;\n\n$app = AppFactory::create();\n\n$app-&gt;get(&#039;\/send&#039;, function (Request $request, Response $response, $args) {\n    $phpmailer = new PHPMailer();\n    $phpmailer-&gt;isSMTP();\n    $phpmailer-&gt;Host = &#039;smtp.mailmug.net&#039;;\n    $phpmailer-&gt;SMTPAuth = true;\n    $phpmailer-&gt;Port = 2525;\n    $phpmailer-&gt;SMTPSecure = &#039;&#039;;\n    $phpmailer-&gt;Username = &#039;lz5ebosxdq0uruxb&#039;; \/\/ https:\/\/mailmug.net\/ create an account\n    $phpmailer-&gt;Password = &#039;kbs6m4hifn8di3gi&#039;;\n    $phpmailer-&gt;setFrom(&#039;from@example.com&#039;, &#039;Mailer&#039;);\n    $phpmailer-&gt;addAddress(&#039;info@example.net&#039;, &#039;Example&#039;);     \/\/Add a recipient\n\n\n    $phpmailer-&gt;isHTML(true);                                  \/\/Set email format to HTML\n\n    $phpmailer-&gt;Subject = &#039;Here is the subject&#039;;\n    $phpmailer-&gt;Body    = &#039;This is the HTML message body &lt;b&gt;in bold!&lt;\/b&gt;&#039;;\n    $phpmailer-&gt;AltBody = &#039;This is the body in plain text for non-HTML mail clients&#039;;\n\n    $phpmailer-&gt;send();\n\n    $response-&gt;getBody()-&gt;write(&quot;email sent&quot;);\n    return $response;\n});\n\n$app-&gt;run();\n<\/pre><\/div>\n\n\n<div style=\"height:55px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Test it<\/h2>\n\n\n\n<p>Start the server and navigate to <strong>http:\/\/your-domain\/send<\/strong> from your browser. Then you can check test emails from <strong>MailMug<\/strong> admin panel. <\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/mailmug-admin.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"274\" data-id=\"42\" src=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/mailmug-admin-1024x274.png\" alt=\"\" class=\"wp-image-42\" srcset=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/mailmug-admin-1024x274.png 1024w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/mailmug-admin-300x80.png 300w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/mailmug-admin-768x205.png 768w, https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/mailmug-admin.png 1254w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<div style=\"height:53px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Configure Production Email Server<\/h2>\n\n\n\n<p>Copy and paste production email server credentials. You will get email server SMTP credentials from cPanel or Plesk. Go to cPanel &gt; Emails &gt; create an email.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Easy-to-follow guide for sending emails from PHP Slim Framework. You can try it out using a fake SMTP account. Step 1: Install PHPMailer library by composer from Packagist Go to php slim root folder by terminal then execute the following command. It will automatically install the email library from Packagist. Step 2: Add the Following [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":47,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Send Email in PHP Slim Framework with Controllers - MailMug Blog<\/title>\n<meta name=\"description\" content=\"Step-by-step instructions to send email from php slim framework. You can easily test with an SMTP sandbox account.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send Email in PHP Slim Framework with Controllers - MailMug Blog\" \/>\n<meta property=\"og:description\" content=\"Step-by-step instructions to send email from php slim framework. You can easily test with an SMTP sandbox account.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\" \/>\n<meta property=\"og:site_name\" content=\"MailMug Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-19T07:23:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-20T03:16:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/slim-php-frmawork-smtp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\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:\/\/mailmug.net\/blog\/email-php-slim-framework\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d\"},\"headline\":\"Send Email in PHP Slim Framework with Controllers\",\"datePublished\":\"2023-08-19T07:23:04+00:00\",\"dateModified\":\"2023-08-20T03:16:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\"},\"wordCount\":158,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\"},\"articleSection\":[\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\",\"url\":\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\",\"name\":\"Send Email in PHP Slim Framework with Controllers - MailMug Blog\",\"isPartOf\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#website\"},\"datePublished\":\"2023-08-19T07:23:04+00:00\",\"dateModified\":\"2023-08-20T03:16:53+00:00\",\"description\":\"Step-by-step instructions to send email from php slim framework. You can easily test with an SMTP sandbox account.\",\"breadcrumb\":{\"@id\":\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mailmug.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Send Email in PHP Slim Framework with Controllers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mailmug.net\/blog\/#website\",\"url\":\"https:\/\/mailmug.net\/blog\/\",\"name\":\"MailMug\",\"description\":\"SandBox SMTP Email Account\",\"publisher\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mailmug.net\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/mailmug.net\/blog\/#organization\",\"name\":\"MailMug\",\"url\":\"https:\/\/mailmug.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"contentUrl\":\"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"width\":320,\"height\":293,\"caption\":\"MailMug\"},\"image\":{\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mailmug.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/mailmug.net\/blog\"],\"url\":\"https:\/\/mailmug.net\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Send Email in PHP Slim Framework with Controllers - MailMug Blog","description":"Step-by-step instructions to send email from php slim framework. You can easily test with an SMTP sandbox account.","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:\/\/mailmug.net\/blog\/email-php-slim-framework\/","og_locale":"en_US","og_type":"article","og_title":"Send Email in PHP Slim Framework with Controllers - MailMug Blog","og_description":"Step-by-step instructions to send email from php slim framework. You can easily test with an SMTP sandbox account.","og_url":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/","og_site_name":"MailMug Blog","article_published_time":"2023-08-19T07:23:04+00:00","article_modified_time":"2023-08-20T03:16:53+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/slim-php-frmawork-smtp.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#article","isPartOf":{"@id":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/"},"author":{"name":"admin","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d"},"headline":"Send Email in PHP Slim Framework with Controllers","datePublished":"2023-08-19T07:23:04+00:00","dateModified":"2023-08-20T03:16:53+00:00","mainEntityOfPage":{"@id":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/"},"wordCount":158,"commentCount":0,"publisher":{"@id":"https:\/\/mailmug.net\/blog\/#organization"},"articleSection":["php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/","url":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/","name":"Send Email in PHP Slim Framework with Controllers - MailMug Blog","isPartOf":{"@id":"https:\/\/mailmug.net\/blog\/#website"},"datePublished":"2023-08-19T07:23:04+00:00","dateModified":"2023-08-20T03:16:53+00:00","description":"Step-by-step instructions to send email from php slim framework. You can easily test with an SMTP sandbox account.","breadcrumb":{"@id":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mailmug.net\/blog\/email-php-slim-framework\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mailmug.net\/blog\/email-php-slim-framework\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mailmug.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Send Email in PHP Slim Framework with Controllers"}]},{"@type":"WebSite","@id":"https:\/\/mailmug.net\/blog\/#website","url":"https:\/\/mailmug.net\/blog\/","name":"MailMug","description":"SandBox SMTP Email Account","publisher":{"@id":"https:\/\/mailmug.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mailmug.net\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/mailmug.net\/blog\/#organization","name":"MailMug","url":"https:\/\/mailmug.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png","contentUrl":"https:\/\/mailmug.net\/blog\/wp-content\/uploads\/2023\/08\/logo.png","width":320,"height":293,"caption":"MailMug"},"image":{"@id":"https:\/\/mailmug.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/97fb32aba211755b8d48bdd54df9c66d","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mailmug.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1e1bdecb54e39d090acd1ba4b20cb7db?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/mailmug.net\/blog"],"url":"https:\/\/mailmug.net\/blog\/author\/admin\/"}]}},"amp_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/19"}],"collection":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/comments?post=19"}],"version-history":[{"count":21,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":72,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/posts\/19\/revisions\/72"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/media\/47"}],"wp:attachment":[{"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/media?parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/categories?post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mailmug.net\/blog\/wp-json\/wp\/v2\/tags?post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}