Learn How to Send Email in PHP with localhost servers. This code works on LAMP, WAMP and XAMPP servers. This code makes use of Gmail’s SMTP Server for PHP mailer script. SMTP is an abbreviated form of Simple Mail Transfer Protocol.
Get complete details on using PHP Mail function using gmail SMTP mail server. This is a very simple php mail script that can be modified. You can modify the php email sender function to send attachments . You can add your CSS scripts later on. There are some steps that should be followed for sending email in PHP localhost to your mailbox.
What is SMTP?
Simple Mail Transfer Protocol is an Internet standard for sending electronic mails. SMTP uses TCP Port 25. SMTPS is an extension to SMTP that includes SSL connections.
E-mail servers and other agents use SMTP to send and receive e-mails. For retrieving messages, client applications usually use either IMAP or POP3.
1. Install SMTP Server
2. Edit SSMTP.CONF File
3. Edit PHP.INI File
1. Install SMTP Mail Server (Linux)
To install the mail server, execute the following command on Linux Terminal.
Now, you will have to configure your php.ini file and ssmtp.conf files.
2. ssmtp.conf configuration:
File Location: /etc/ssmtp/ssmtp.conf
This code will send php email using Gmail’s SMTP Server. Change AuthUser and AuthPass as per your preference. Gmail IDs work efficiently here.
3. php.ini configuration
File Location: /etc/php/7.0/apache2/php.ini
Configure the PHP Mail Function here. Search for [mail function] and replace the following code. The sendmail_path has been modified here.
Now, try sending an email. If you have any errors in this guide to send email in PHP using PHP Mail function in LAMP, WAMP or XAMPP, let us know about it in the comment section below.