Android
Wordpress

Hello Everyone, Today we are going to learn,

“How to Send Emails Using PHPMailer Through PHP ?”.

Let me first give you some basic information about PHPMailer ,

It is a code library to send emails safely ans easily via PHP from a web server.

Is it an alternative to PHP’s mail() function?

In most cases, it’s an alternative to PHP’s mail() function, but there are many other cases where the mail() function is simply not flexible enough to achieve what you need.

How to Install PHPMailer ?

You can install using COMPOSER.

OR, You can download it from HERE.

NOTE : I HAVE INSTALL IT VIA COMPOSER

Sending Email from Local Web Server using PHPMailer.

Here is the simple example of sending email from local we server.

Sending an E-Mail with Attachments 

Let’s see an example on how to send an email with attachments.

Here we are attaching two files i.e., file.txt which resides in the same directory as the script and images/profile.png which resides in images directory of the script directory.

Using SMTP

You can use the mail server of an another host to send email, but for this you first need to have authentication.

For example: to send an email from Gmail’s mail server you need to have a Gmail account.

SMTP is a protocol used by mail clients to send an email send request to a mail server. Once the mail server verifies the email it sends it to the destination mail server.

Here is an example of sending an email from Gmail’s mail server from your domain. You don’t need a local mail server to run the code. We will be using the SMTP protocol:

This is it. Now you can send email using PHPMailer through PHP.

Happy Coding!

Cheers!

LEAVE A REPLY

Please enter your comment!
Please enter your name here