How To Send an Email Via Cpanel Smtp Server In Laravel 10

How To Send an Email Via Cpanel Smtp Server In Laravel 10

Hello guys!!! in this post, I will show you how to send an Email via Cpanel Smtp Server In Laravel 10. So let’s get started…

You have a Laravel-livewire contact form to which you would like to send emails. For instance like this…

How would you go about it?

Step 1:

Login to your Cpanel from your shared hosting provider using the login credentials. Once you’re in click on the Cpanel login. This link will take you to the Cpanel tools.

cpanel host

Step 2: 

Type email accounts on the search tools within your cpanel dashboard tools and click on the email accounts suggestion keyword. Here you will be taken to the Email accounts page.

email accounts

Step 3:

Within the emails accounts detail page you will see a list of emails you’ve created so far.

If you don’t have one you can create one by clicking on the create button whereby you will be taken to the email account creation page.

Step 4:

Once you’re done setting up an email in case you have not. Go back to the list of created emails, you can click on the connected devices. You will be taken to the Set Up Mail Client for “Your email” 

Sending an Email:

To send an email when the contact form is submitted, follow these steps:

a. Configure SMTP Settings:

In your .env file, set the mail configuration to use SMTP:

MAIL_MAILER=smtp
MAIL_HOST=your_host
MAIL_PORT=your_port
MAIL_USERNAME=your_email_username
MAIL_PASSWORD=your_email_password
MAIL_ENCRYPTION=encryption_type (usually tls or ssl)
MAIL_FROM_ADDRESS=from_email_address
MAIL_FROM_NAME="From Name"

Replace the placeholders (your_host, your_port, etc.) with the appropriate values provided by your shared hosting provider. e.g

Let’s break this down:

  1. MAIL_MAILER=smtp: This tells your app to use “SMTP” (Simple Mail Transfer Protocol) to send emails. Think of SMTP as the postman who delivers your letters.
  2. MAIL_HOST= “your host provider This is the address of the post office (or server) where your emails are sent from and received. It’s like the main building where the postman (SMTP) works.
  3. MAIL_PORT=587: This is like a specific door number at the post office. The postman knows to use door number “587” when delivering or picking up your letters.
  4. MAIL_USERNAME= “your email account This is your unique name tag. It tells the post office that the emails belong to “your email account”.
  5. MAIL_PASSWORD= “your email account password This is the secret handshake or key that proves you are the real “your email account”. It keeps your emails safe from others.
  6. MAIL_ENCRYPTION=tls: This is like a special seal on your letters that keeps them private. “TLS” is a method to make sure no one can read your letters while they’re being delivered.
  7. MAIL_FROM_ADDRESS=” your email account: When you send a letter, this is the return address on the envelope. It tells recipients that the email came from “your email account”.
  8. MAIL_FROM_NAME=”${APP_NAME}”: This is the name that appears on the letter, like “From Brian’s App”. If your app’s name is “WebDev Trainee”, then the email will show it’s

1. Difference between Port 587 and Port 465:

Both 587 and 465 are ports used for sending emails, but they have different historical and practical applications:

  • Port 587: This is the default port for SMTP Submission. It’s used when mail clients (like Outlook or Thunderbird) send emails to a mail server. It’s designed to be used for submitting messages to mail servers. Typically, port 587 uses the STARTTLS command for upgrading a plaintext connection to an encrypted (TLS or SSL) connection.
  • Port 465: This was originally registered for SMTPS (SMTP over SSL). SSL (Secure Sockets Layer) was used to secure the connection from the start. However, port 465 was deprecated in favor of 587 for SMTP Submission. Some providers still offer SMTP over port 465 as a legacy option, but it’s not a standard.

2. Difference between SSL and TLS:

SSL (Secure Sockets Layer) and TLS (Transport Layer Security) are both cryptographic protocols designed to provide secure communication over a computer network. They’re like special codes that keep your messages secret while they travel.

  • SSL (Secure Sockets Layer): This is the older version of the protocol. It was developed by Netscape in the mid-1990s. There were several versions of SSL, but due to vulnerabilities and security issues, it’s now considered obsolete and insecure. The last version of SSL was SSL 3.0.
  • TLS (Transport Layer Security): This is the successor to SSL and is the modern way to achieve secure communications. It began with TLS 1.0 (which is essentially SSL 3.1) and has had several versions since, with TLS 1.3 being the latest. It’s more secure and efficient than its predecessor.

To use an analogy: Imagine SSL as an old lock and key, and TLS as a modern electronic security system. While both serve the purpose of securing a door, the electronic system (TLS) is more advanced and offers better protection than the old lock and key (SSL).

Step 5:

You can now send your message…

Email Forwarder

To have the messages reach you directly I mean in your Gmail box. You can add an Email forwarder. For example, forward joe@example.com to joseph@example.com so that you only have one inbox to check.

 

Sign up for free tutorials in your inbox.

We don’t spam! Read our privacy policy for more info.

Leave a Comment

Your email address will not be published. Required fields are marked *