PHPMailer: Examples, Debugging, SMTP Settings | Mailtrap Blog (2023)

When it comes to adding email functionality to your PHP app, PHPMailer class is the winning option. It is compatible with most of the PHP frameworks (Laravel or Symfony are based on the SwiftMailer library, though, but it is still possible to use PHPMailer as well.) PHPMailer provides powerful functionality to create HTML emails with attachments and send them to multiple recipients via SMTP or a local webserver. Learn how to easily use all these options in this tutorial!

What is PHPMailer

PHPMailer is the classic email sending library for PHP. It supports several ways of sending email messages such as mail(), Sendmail, qmail, and direct dispatch to SMTP servers. In addition, it provides a list of advanced features:

  • SMTP authentication
  • secure/MIME encryption
  • support of TLS and SSL protocols
  • HTML content along with plain text
  • multiple fs, string, and binary attachments
  • embedded images support

Sending Email With PHPMailer and SMTP

To send emails with PHPMailer and SMTP, you need to install PHPMailer and configure SMTP settings first.

How to install PHPMailer

Up to version 5, PHPMailer was providing “PHPMailerAutoload.php” file, so all that was needed was to include it in your script and create a PHPMailer instance.Starting from PHPMailer 6.0 release in August 2017, you need to install it, preferably via Composer, a dependency manager for PHP (this way is recommended by PHPMailer’s creators on Github). After installing Composer, add this line to your composer.json file:

"phpmailer/phpmailer": "~6.1"

or run

composer require phpmailer/phpmailer

If you don’t want to install Composer, for example, while working within a testing environment, you can add PHPMailer manually. Download files with PHPMailer source code, then copy the contents of the PHPMailer folder to one of the include_path directories specified in your PHP configuration, and load each class file manually:

<?phpuse PHPMailer\PHPMailer\PHPMailer;use PHPMailer\PHPMailer\Exception;require 'path/to/PHPMailer/src/Exception.php';require 'path/to/PHPMailer/src/PHPMailer.php';require 'path/to/PHPMailer/src/SMTP.php';

Adding Exception class will help you handle errors and debug them. In PHP it works similarly to the other programming languages. So, without it, if there is an error in your email sending code, you will just see a message saying Exception class is not found, but you won’t be provided with any details on how to debug it. We will describe debugging is a separate section of this post.

To see detailed instructions on installation, check PHPMailer documentation on Github.

SMTP configuration

How to send test messages with PHPMailer?

To test PHP mail functionality, we will use Mailtrap, a fake SMTP server, so as not to flood our inboxes or even worse, the inboxes of our customers. Once you make sure that everything works properly and your email messages look right, you will be able to easily substitute the SMTP settings in our examples with your real server’s.

If you are not using Mailtrap yet, create a free account , go to your Inbox, and copy the following values from the SMTP settings tab to your PHPMailer script:

server host ($mail->Host = ’’)username ($mail->Username = ‘1a2b3c4d5e6f7g’ (example, generated by Mailtrap)password ($mail->Password = ‘1a2b3c4d5e6f7g’ (example, generated by Mailtrap)and port ($mail->Port = 25, or 465, or 2525

There is one more point left to mention about SMTP: POP-before-SMTP for authentication. This method is almost fully replaced by the SMTP authentication but still can be used sometimes. Its main advantage is the transparency for the user who is sending an email. Check this Github page to get the example of using POP-before-SMTP with PHPMailer.

(Video) Using phpmailer sending Emails in PHP from localhost with SMTP

Test Your Emails Now

Sending HTML email via SMTP with PHPMailer

Most likely, you will use HTML to design your email notification. So, let’s review some examples of using HTML methods and attributes.

Basic HTML message

If you have used Composer for installation, include the Composer generated autoload.php file:

require 'path/to/composer/vendor/autoload.php';

If you have installed PHPMailer manually, initialize it like this:

require path/to/PHPMailer/src/PHPMailer.php';require path/to/PHPMailer/src/SMTP.php';require path/to/PHPMailer/src/Exception.php';

Then create the PHPMailer class:

<?phpuse PHPMailer\PHPMailer\PHPMailer;

The next step is to create a new PHPMailer object:

$mail = new PHPMailer();

Now let’s move to an SMTP configuration:

$mail->isSMTP();$mail->Host = '';$mail->SMTPAuth = true;$mail->Username = '1a2b3c4d5e6f7g'; //paste one generated by Mailtrap$mail->Password = '1a2b3c4d5e6f7g’ //paste one generated by Mailtrap$mail->SMTPSecure = 'tls';$mail->Port = 2525;

Specify PHPMailer headers:

$mail->setFrom('', 'Mailtrap');$mail->addReplyTo('', 'Mailtrap');$mail->addAddress('', 'Tim');$mail->addCC('', 'Elena');$mail->addBCC('', 'Alex');

If you need to add several addresses, specify each of them as a new command:

$mail->AddBCC('', 'Anna');$mail->AddBCC('', 'Mark');

With PHPMailer, you can loop your message and send it to multiple recipients. In particular, you can read a list from the table. We will review such examples a bit later in this post, and now let’s get back to our basic message.

Set a subject:

$mail->Subject = 'Test Email via Mailtrap SMTP using PHPMailer';

Then set the email format to HTML with isHTML(true) property:


Now you can input the desired content:

$mailContent = "<h1>Send HTML Email using SMTP in PHP</h1> <p>This is a test email I’m sending using SMTP mail server with PHPMailer.</p>";$mail->Body = $mailContent;

With PHPMailer, you can also make a nice HTML email, with custom formatting, images, and send emails with attachments. For your convenience, PHPMailer provides an option to read an HTML message body from an external file, convert referenced images to embedded as well as convert HTML into a basic plain-text alternative body. This way, you will not overload your message sending code with HTML and will be able to update your HTML template independently. To include a separate HTML file, add these attributes:

(Video) Using phpmailer sending Emails with attachments in PHP from localhost with SMTP

$mail->msgHTML(file_get_contents('contents.html'), __DIR__);

In the end, specify the email sending attributes:

if($mail->send()){ echo 'Message has been sent';}else{ echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo;}

The result “Message has been sent” informs you that your code executes correctly. To check the delivery result and details, go to your Mailtrap inbox: your messages will get there in seconds.

With Mailtrap, you will be able to review your HTML code, raw data, perform email browser testing as well as make sure your message won’t be marked as spam, or your sending domain won’t go blacklisted.

Capture all test emails and inspect them all in one place.

HTML email with attachments

There are two options for adding files to your message:

  • Enclose a file from your filesystem – like you can make it in the email client. In this case, your files should be saved in the same directory as the script.
    • Also, a file can be inlined into your message, this is valid for images.
  • Add a string attachment – in this case, the data stored in a variable is attached to the message. It can be extracted from a database, from example, so you don’t need to save it as a file, actually.

To attach a file, you just need to specify its path. Also, you can add a filename but it’s optional: the script will use the actual name of your file:

$mail->addAttachment('path/to/invoice1.pdf', 'invoice1.pdf');

To add another file, repeat the command:

$mail->addAttachment('path/to/calculation1.xlsx', 'calculation1.xlsx');

To add an attachment from the string, use addStringAttachment() command. You should pass the content and the filename:

$mysql_data = $mysql_row['blob_data'];$mail->addStringAttachment($mysql_data, 'db_data.db'); 

This is an example of adding data stored as a BLOB (Binary Large OBject) from MySQL database.

Alternatively, you can use a remote URL, like below:

$mail->addStringAttachment(file_get_contents($url), 'myfile.pdf');

To embed an image, we use CID attachments here:

$mail->addEmbeddedImage('path/to/image_file.jpg', 'image_cid');$mail->isHTML(true);$mail->Body = '<img src="cid:image_cid">';

Finally, let’s review an example of a whole message with an inlined image and internal HTML body:

<?phpuse PHPMailer\PHPMailer\PHPMailer;require 'path/to/composer/vendor/autoload.php';$mail->isSMTP();$mail->Host = '';$mail->SMTPAuth = true;$mail->Username = 'paste one generated by Mailtrap';$mail->Password = 'paste one generated by Mailtrap’$mail->SMTPSecure = 'tls';$mail->Port = 2525;$mail->setFrom('', 'First Last');$mail->addReplyTo('', 'John Doe';$mail->isHTML(true);$mail->Subject = "PHPMailer SMTP test";$mail->addEmbeddedImage('path/to/image_file.jpg', 'image_cid');$mail->Body = '<img src="cid:image_cid"> Mail body in HTML';$mail->AltBody = 'This is the plain text version of the email content';if(!$mail->send()){ echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo;}else{ echo 'Message has been sent';

The result “Message has been sent” informs you that your code is executing correctly. To check the delivery result and details, go to your Mailtrap inbox: your messages will get there in seconds.

PHPMailer: Examples, Debugging, SMTP Settings | Mailtrap Blog (1)
(Video) Google Remove Allow Less Secure Apps Option - Alternative Solution | What To do Now ? | Web Tech

With Mailtrap, you will be able to review your HTML code, raw data, perform email browser testing as well as make sure your message won’t be marked as spam, or your sending domain won’t go blacklisted.

Once you have verified that your PHPMailer sending result matches your expectations, you can switch to regular email sending via any preferred SMTP server.

Sending emails to multiple recipients

Above we have examined how to send one and the same email to several recipients, including CCing and BCCing. What if you need to send a modified message to a list of recipients, which is often required for transactional emails? PHPMailer offers features for such use cases as well!

<?phpuse PHPMailer\PHPMailer\PHPMailer;require 'path/to/composer/vendor/autoload.php';$mail = new PHPMailer;$body = file_get_contents('contents.html');$mail->isSMTP();$mail->Host = '';$mail->SMTPAuth = true;$mail->Username = '1a2b3c4d5e6f7g'; //generated by Mailtrap$mail->Password = '1a2b3c4d5e6f7g'; //generated by Mailtrap$mail->SMTPSecure = 'tls';$mail->Port = 2525;$mail->SMTPKeepAlive = true; // add it to keep SMTP connection open after each email sent$mail->setFrom('', 'List manager');$mail->Subject = "New Mailtrap mailing list";$users = [ ['email' => '', 'name' => 'Max'], ['email' => '', 'name' => 'Bob']];foreach ($users as $user) { $mail->addAddress($user['email'], $user['name']); $mail->Body = "<h2>Hello, {$user['name']}!</h2> <p>How are you?</p>"; $mail->AltBody = "Hello, {$user['name']}! \n How are you?"; try { $mail->send(); echo "Message sent to: ({$user['email']}) {$mail->ErrorInfo}\n"; } catch (Exception $e) { echo "Mailer Error ({$user['email']}) {$mail->ErrorInfo}\n"; } $mail->clearAddresses();}$mail->smtpClose();

Test emails like this in a safe testing environment.

How to use PHPMailer with Gmail

Gmail is one of the most popular SMTP servers, which allows you to send emails for free. However, it does require some tinkering with authentication settings.


Here are the basic Gmail SMTP credentials:

$mail->SMTPSecure = 'tls';$mail->Host = '';$mail->Port = 587;


$mail->SMTPSecure = 'ssl';$mail->Host = '';$mail->Port = 465;

If you don’t use the 2-step verification for your account, use your Gmail address and password to your Gmail account.

You should Allow less secure apps in your account settings. Please note that it may take an hour or two for this setting to come into effect. In some cases, you might additionally need to make necessary changes on the unlock CAPTCHA page.

If something goes wrong, you will receive an error “5.7.14 Please log in via your web browser and then try again” or “Username and Password not accepted”. It should contain instructions on how to fix it.

2-Step Verification

If 2-step verification is enabled for your Gmail account and you wish to use it with PHPMailer as well, you will need to create an App password to continue. It is a 16-digit passcode, which you should put as a value to $mail->Password. It is easy to generate one following these Google instructions.


OAuth2 is the most complicated but still the recommended method. Fortunately, there is oauth2-google. It is a package to support Google OAuth 2.0 for the PHP League’s OAuth 2.0 Client. It supports PHP 7.0 – PHP 7.3. To use it, you need to get a Google client ID and client secret first. Follow this Google’s guide to set everything up.Once completed, install the package with composer and add the authorization details as below:

composer require league/oauth2-googleuse League\OAuth2\Client\Provider\Google;$provider = new Google([ 'clientId' => '{google-client-id}', 'clientSecret' => '{google-client-secret}', 'redirectUri' => '',]);

For more details, follow the oauth2-google on GitHub.

(Video) HTML from to Email using SMTP in PHP with Source code - Send email using phpmailer

Send an email with PHPMailer without SMTP server

An SMTP transport option is the most popular and usable with PHPMailer. However, as we’ve already mentioned, it supports other ways as well.

For localhost, you can use the standard Sendmail program:

// Set mailer with this method$mailer->isSendmail();// And send mail as usual$mailer->send();

If you prefer Unix, then use qmail:

// Set mailer with this method$mailer->isQmail();// And send mail as usual$mailer->send();


If you experience some troubles when sending emails through an SMTP server, the SMTPDebug command will help you explore those errors and find out what should be fixed.

Enable SMTP debugging and set the debug level in your script as follows:

$mail->SMTPDebug = 2;
  • level 1 = client; will show you messages sent by the client
  • level 2 = client and server; will add server messages, it’s the recommended setting.
  • level 3 = client, server, and connection; will add information about the initial information, might be useful for discovering STARTTLS failures
  • level 4 = low-level information.

Use level 3 or level 4 if you are not able to connect at all. Setting level 0 will turn the debugging off, it is usually used for production.

For a better understanding of how debugging in PHPMailer works, let’s review a couple of examples.

Example1. Invalid SMTP hostname

2018-12-12 14:51:32Connection: opening to, timeout=10, options=array()2018-12-12 14:51:42Connection failed. Error #2: stream_socket_client(): unable to connect to (Operation timed out) [/Users/xxxx/Downloads/PHPMailer/src/SMTP.php line 326]2018-12-12 14:51:42SMTP ERROR: Failed to connect to server: Operation timed out (60)2018-12-12 14:51:42SMTP connect() failed.Mailer Error: SMTP connect() failed. 

For this example, we entered an invalid hostname: instead of and instantly received a message that an error has occurred at the very first stage of communication with the server.

Example 2. Invalid credentials

2018-12-12 14:49:26Connection: opening to, timeout=300, options=array()2018-12-12 14:49:26Connection: opened2018-12-12 14:49:26SMTP INBOUND: "220 ESMTP ready"2018-12-12 14:49:26SERVER -> CLIENT: 220 ESMTP ready...2018-12-12 14:49:30SMTP INBOUND: "535 5.7.0 Invalid login or password"2018-12-12 14:49:30SERVER -> CLIENT: 535 5.7.0 Invalid login or password2018-12-12 14:49:30SMTP ERROR: Username command failed: 535 5.7.0 Invalid login or password2018-12-12 14:49:30SMTP Error: Could not authenticate.2018-12-12 14:49:30CLIENT -> SERVER: QUIT2018-12-12 14:49:30SMTP INBOUND: "221 2.0.0 Bye"2018-12-12 14:49:30SERVER -> CLIENT: 221 2.0.0 Bye2018-12-12 14:49:30Connection: closed2018-12-12 14:49:30SMTP connect() failed.Mailer Error: SMTP connect() failed. 

This example demonstrates where the error occurs: now the SMTP, its hostname, and port are valid but a combination of login and password was not found, so you should double-check and modify your credentials.

There are a couple of detailed articles on GitHub about debugging and troubleshooting, refer to them when you need to dive deeper into these topics.

What else you should know about PHPMailer

In this tutorial we have reviewed the most common PHPMailer use cases: creating HTML emails with images and attachments, sending them via SMTP or localhost to different types of recipients along with debugging options.

If you need more specific examples, check the “examples” folder inside PHPMailer documentation on Github.

(Video) [SOLVED] PHPMailer SMTP Error Could not connect to SMTP host


Does PHPMailer use SMTP? ›

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.

How do I debug PHPMailer? ›

Enable SMTP debugging and set the debug level in your script as follows: $mail->SMTPDebug = 2; level 1 = client; will show you messages sent by the client. level 2 = client and server; will add server messages, it's the recommended setting.

How do I use PHPMailer? ›

Open the Command prompt and go to the directory of the project in which you want to use PHPMailer.
Add the content.
  1. isHTML(): If passed true, sets the email format to HTML.
  2. Subject: Set the subject of the Mail.
  3. Body: Set the contents of the Mail.
  4. AltBody: Alternate body in case the e-mail client doesn't support HTML.
Aug 23, 2019

How do I know if PHPMailer is working? ›

to check if it is sending mail as intended; <? php $email = ""; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>

What is SMTP username in PHPMailer? ›

PHPMailer Script to Send Email Using SMTP Authentication

FromName: the sender's name. AddAddress: the recipient's email address and name. AddReplyTo: the reply-to email address and name. Username: your SMTP username. Password: your SMTP password.

How does SMTP authentication work? ›

SMTP Authentication is the mechanism by which the clients of an ISP identify themselves to the mail server through which they intend to send email. It is not possible for any person to send email via any mail server they choose; mail servers will only allow the sending of email by legitimate users.

How do I fix SMTP connection error? ›

  1. Check the SMTP server settings. SMTP server address—Check the host name or network address of the SMTP e-mail server. ...
  2. Check the SMTP authentication settings. Check whether the e-mail server requires authentication. ...
  3. Test SMTP settings by sending a test e-mail. If you are unable to send a test e-mail:

How do I fix SMTP error? ›

How to fix issues with sending email (SMTP)
  1. Open the settings for your email in the application or device you are using.
  2. Locate the outgoing SMTP server and its settings.
  3. Check the current outgoing port and change it to 26 or 587.
  4. Make sure any username and password fields are filled in if shown.
  5. Save changes and test.

How do you fix mailer error SMTP connect () failed? ›

How to fix it?
  1. Modify the server's firewall rules to permit outbound connections on ports such as 465.
  2. Change the server's SMTP restrictions. ...
  3. Edit PHPMailer's configuration settings, such as host and port.
  4. Correct DNS resolution for the mail server.
Nov 18, 2021

Does PHPMailer work on localhost? ›

The PHPMailer library provides the easiest way to send an email from localhost with an SMTP server using PHP. Not only the text email, but you can also send HTML email from localhost in PHP using PHPMailer.

How do I stop emails going to spam in PHPMailer? ›

usually this happens because the sending server is already marked as spam by somebody. The way i found is go to the gmail account mark the item as 'important' in gmail and 'Add to Safe senders' in Outlook.

What is SMTP username and password? ›

Your SMTP username is your email account and the SMTP password is the password for your email account.

How do I access my SMTP host? ›

To connect to an SMTP server by using Telnet on port 25, you need to use the fully-qualified domain name (FQDN) (for example, or the IP address of the SMTP server. If you don't know the FQDN or IP address, you can use the Nslookup command-line tool to find the MX record for the destination domain.

Can't connect to SMTP server? ›

1 SMTP Status appears when no answer is received from the host or when the connection is lost. This could be due to a temporary issue with their network or mail server or due to a configuration within your middleware (firewall, antivirus, etc.) blocking the connectivity.

Why is PHP not sending email? ›

Make sure the localhost mail server is configured

Without one, PHP cannot send mail by default. You can overcome this by installing a basic mail server. For Windows you can use the free Mercury Mail. You can also use SMTP to send your emails.

What is an SMTP server name? ›

SMTP stands for Simple Mail Transfer Protocol, and it's an application used by mail servers to send, receive, and/or relay outgoing mail between email senders and receivers.

How do I send PHP mail via SMTP? ›

Writing the PHP Code to Send Email using Gmail SMTP
  1. Step 1: Download PHPMailer library from this github link. ...
  2. Step 2: Writing the PHP Code to make an SMTP connection. ...
  3. Step 3: Include packages and files for PHPMailer and SMTP protocol: ...
  4. Step 4: Initialize PHP Mailer and set SMTP as mailing protocol:
Aug 9, 2022

How do you setup configure SMTP you can find on PHP Net? ›

The php. ini File
  1. Open your php. ini file (if you don't know where this is, see below)
  2. Search for the line that reads [mail function]
  3. Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP.
  4. Save/close the php. ini file.
  5. Restart your web server.

Can I use SMTP without authentication? ›

You can't use gmail smtp-server without authentication. It's a google policy. You need to enter your account password.

How do I generate SMTP credentials? ›

  1. Open the Amazon SES console. ...
  2. Because SMTP credentials are Regional, confirm you're in the correct Region. ...
  3. From the navigation pane, under Email Sending, choose SMTP Settings.
  4. Choose Create My SMTP Credentials.
  5. After the new page loads, review the value in IAM User Name. ...
  6. Choose Create.

How do I know if SMTP AUTH is enabled? ›

To enable or disable SMTP AUTH, there is a new checkbox available for Active Users with a mailbox in Office 365—”Authenticated SMTP.” This is found by clicking the user in Active Users, Mail, then Manage email apps.

How do I reset my SMTP server? ›

Windows Mail
  1. Start Windows Mail, click the Tools menu at the top of the window and then click Accounts.
  2. Select your account under Mail, and then click on the Properties button.
  3. Go to the Advanced tab, under Outgoing server (SMTP), change port 25 to 587.
  4. Click the OK button to save the changes.

What is SMTP error while sending mail? ›

SMTP is an internet standard used by mail servers to send and receive email. SMTP error messages help you understand why a message wasn't sent successfully. If incoming or outgoing messages are bouncing, check the bounce messages for an SMTP error code that can help you diagnose the problem.

What are SMTP commands? ›

SMTP commands
SubcommandSupported by SMTP ServerDescription
EHLONOIdentifies the domain name of the sending host to SMTP.
EXPNYESVerifies whether a mailbox exists on the local host.
HELOYESIdentifies the domain name of the sending host to SMTP.
HELPYESProvides help with SMTP commands.
11 more rows

Is Gmail an SMTP server? ›

Use the Gmail SMTP server

If you connect using SSL or TLS, you can send mail to anyone inside or outside of your organization using as your server. This option requires you to authenticate with your Gmail or Google Workspace account and passwords.

How do I enable SMTP in Gmail? ›

  1. In your Google/Gmail account, go to Settings.
  2. Select the 'Forwarding and POP/IMAP' settings.
  3. Under the 'IMAP access' section, toggle on the option to 'Enable IMAP. ...
  4. In your Accredible instance, click on 'Emails' at the top of your Accredible dashboard.
  5. In the left-hand sidebar menu, click on 'SMTP Overrides.

How send mail from localhost PHP to xampp? ›

The Steps To Send Mail From Localhost XAMPP Using Gmail:
  1. Open the XAMPP installation directory.
  2. Navigate php.ini file from C:\xampp\php.
  3. Press ctrl + f to find the mail function.
  4. Search & pass the below-mentioned values. ...
  5. Open sendmail. ...
  6. Press ctrl + f & find sendmail.
Jan 21, 2021

Why do emails go to spam instead of Inbox PHP? ›

If script is wrong then all mail should go into spam or if right then all mail into inbox. Why some mail goes into spam and some in inbox? while subject, body, message and email(to) is same. You should look into an authenticated SMTP solution that uses proper rDNS, DKIM, and SPF records.

How does PHP mail work? ›

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters. mail( to, subject, message, headers, parameters );

How do you send an email from a website? ›

There are 2 basic ways you can send an email from a web page: with the built in HTTP method using the 'mailto' attribute of a hyperlink or by using a server side script.

Where can I find SMTP credentials? ›

View the user's details:
  • If you're generating SMTP credentials for yourself: Open the Profile menu ( ) and click User Settings.
  • If you're an administrator generating SMTP credentials for another user: Open the navigation menu and click Identity & Security. Under Identity, click Users.

What is my SMTP server password? ›

Note: The default username is "admin" (case sensitive), and the default password is "1111". Select Configuration OverView. Select E-mail > Settings > SMTP > Settings.

What is the SMTP port number for Gmail? ›

The outgoing SMTP server, , requires TLS. Use port 465 , or port 587 if your client begins with plain text before issuing the STARTTLS command.

How can I tell if an email is sent in PHP? ›

Well mail() simply returns a boolean value depending on whether the mail was successfully accepted for delivery. From the site: Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

How do I send an email using sendmail? ›

Once logged in, you can run the following command to send email: [server]$ /usr/sbin/sendmail Subject: Test Send Mail Hello World control d (this key combination of control key and d will finish the email.)

How do I send PHP mail via SMTP? ›

Writing the PHP Code to Send Email using Gmail SMTP
  1. Step 1: Download PHPMailer library from this github link. ...
  2. Step 2: Writing the PHP Code to make an SMTP connection. ...
  3. Step 3: Include packages and files for PHPMailer and SMTP protocol: ...
  4. Step 4: Initialize PHP Mailer and set SMTP as mailing protocol:
Aug 9, 2022

Does PHPMailer work on localhost? ›

The PHPMailer library provides the easiest way to send an email from localhost with an SMTP server using PHP. Not only the text email, but you can also send HTML email from localhost in PHP using PHPMailer.

What is an SMTP server name? ›

SMTP stands for Simple Mail Transfer Protocol, and it's an application used by mail servers to send, receive, and/or relay outgoing mail between email senders and receivers.

What is the SMTP protocol? ›

What Is Simple Mail Transfer Protocol (SMTP)? SMTP is used to send and receive email. It is sometimes paired with IMAP or POP3 (for example, by a user-level application), which handles the retrieval of messages, while SMTP primarily sends messages to a server for forwarding.


1. Using sendmail.exe sending Emails in PHP from localhost with SMTP
2. PHPMailer Tutorial: Send an Email via SMTP with GMail
(Senaid Bacinovic)
3. How to Set the Correct Outlook SMTP Settings to Send Emails
4. How to Setup Gmail SMTP Server (Update)
5. Send Mail in PHP Using PHPMailer Gmail SMTP
(Tech. Rudranshi)
6. Fix Email Issues in CyberPanel with SMTP Relay Setup (Free Method)
Top Articles
Latest Posts
Article information

Author: Duncan Muller

Last Updated: 01/15/2023

Views: 6619

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.