MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How can send a mail with Attachment using laravel 5.5

Step:1- composer create-project laravel/laravel mail
or
composer create-project –prefer-dist laravel/laravel mail “5.8.*”

Terminal running composer create-project laravel/laravel mail, installing Laravel v5.8.35

Step:2 – Create Controller php artisan make:controller:SendEmailController This command will make SendEmailController.php file in app/Http/Controllers

Terminal running php artisan make:controller SendEmailController with Controller created successfully

Step:3- Go to the this path app/Http/Controllers/SendEmailController.php copy this code all and paste in this controller page SendEmailController.php

Step 4 – Create View Contact Form

Now we would make a view file for the display contact form on the web page. Below you can find the source code of contact form view file.

VS Code showing send_email.blade.php contact form view with name, email and message fields

Step 5 – Set Route we have created under the Controller file. So here we will make two methods like index() and send() method under the controller. For this, we have to go to routes/web.php to set the route.

Routes/web.php with GET /sendemail and POST /sendemail/send routes to SendEmailController

Step 6 – Create a Mailable class first you have to create an account in mailtrap or click this url https://mailtrap.io/ after create account you have to copy Username: XXXXXXXXX and password: XXXXXXXXXX and put in .env file see pic

Laravel .env file with MAIL_DRIVER smtp, MAIL_HOST smtp.mailtrap.io, port 2525 and masked credentials
Mailtrap SMTP credentials panel showing host smtp.mailtrap.io, ports, and hidden username and password

Step:7- Now we are ready for make mailable class for this we have to go teminal and write following command. php artisan make:mail SendMail

Terminal running php artisan make:mail SendMail with Mail created successfully

This command will make SendMail.php file inside App\Mail\SendMail.php. In this class we have to define one property with name $data, by using this property we can pass data at the time of create an new instance of this class. App\Mail\SendMail.php

Step: 8 – Make View file for Email Body resources/views/dynamic_email_template.blade.php

Dynamic_email_template.blade.php email body using $data first_name and message values

Step:9- php artisan serve run this command and put url in your browser http://127.0.0.1:8000/sendemail

Laravel Send a mail with Attachment form at 127.0.0.1:8000/sendemail with name, email, message and upload fields

Ste

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
sam
MotoShare.in is your go-to platform for adventure and exploration. Rent premium bikes for epic journeys or simple scooters for your daily errands—all with the MotoShare.in advantage of affordability and ease.

Related Posts

AWS IAM Policy to Protect SES SMTP

You can lock down Amazon SES SMTP credentials with an IAM policy on the IAM user that owns them. A Deny on aws:SourceIp limits which IP addresses…

Read More

How to see number of emails sent using smtp in laravel

Laravel does not count or log SMTP emails by default, so a grep will only return a real number once your application writes one log line for…

Read More

PHP Code for Godaddy VPS Server SMTP Email Relay

This page shows how to send email from a GoDaddy VPS through GoDaddy's SMTP relay on port 25 with plain PHP sockets and no extra libraries. Below…

Read More

Email Authentication & Communication Infrastructure in Modern DevOps: The 2026 Definitive Guide

In the high-stakes world of modern DevOps, we spend our days (and sometimes our nights) obsessing over the “golden signals” of site reliability: latency, traffic, errors, and…

Read More

The 5 Most Popular Email APIs Among Developers In 2026

In the modern world, where everything is going digital, email is among the most important means of communication both in personal and business life. As a developer,…

Read More

Senior Exchange Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path

The Senior Exchange Administrator is accountable for the reliability, security, performance, and lifecycle management of the organization’s Microsoft messaging platform, typically spanning Exchange Online (Microsoft 365), Exchange Server (on-premises), or a hybrid configuration. This role ensures email and calendaring services are highly available, compliant, and aligned to business needs while proactively reducing operational risk and improving user experience.

Read More