We use cookies
This site uses cookies from cmlabs to deliver and enhance the quality of its services and to analyze traffic..
We use cookies
This site uses cookies from cmlabs to deliver and enhance the quality of its services and to analyze traffic..
Last updated: Oct 13, 2023
The eventualities are an inevitability that drives every business player to prepare scenarios and adapt. Watch the Anti-Trivial podcast featuring Mas Rochman, Bro Jimmy, and Pak Agus; a combination of a business practitioner, investor, and company leader, discussing how to enhance the foresight of business leaders in welcoming 2025. Don’t miss this special year-end edition of cmlabs Class, Episode 24 with title "New vs Conventional Search Engine. Prepare for the Eventualities!"
See Event DetailsSMTP, which stands for Simple Mail Transfer Protocol, serves as a crucial cornerstone within the global framework of email communication
At its core, an SMTP server possesses the vital role of dispatching emails seamlessly across various computer networks.
But how does this happen? If you look from the perspective of the SMTP function, this protocol collaborates with the Message Transfer Agent (MTA) to send emails.
Within this interplay, the MTA is responsible for controlling the Simple Mail Transfer Protocol during the sending process.
Beyond its active engagement in facilitating email transmission, this protocol also serves as a security measure for filtering incoming emails.
In order to better understand the concepts of the Simple Mail Transfer Protocol, let's delve into the explanation regarding its functions, working mechanism, and activation below.
As mentioned earlier, the function is mainly to ensure secure, reliable, and efficient email communication across computer networks.
However, apart from that, this protocol also serves several other functions in the email-sending process. Here are some of the SMTP functions you need to know:
As a protocol that involves several important stages in the email-sending process, the main steps about how it works include:
The process begins with the sender composing an email message. This message includes the recipient's email address, subject, content, attachments, and other information.
Once the message is composed, the sender sends it to the email server using the MUA (Mail User Agent), a program used to send and receive emails.
After composing the email, you can submit it to the Gmail SMTP server over TCP port 25.
The next step involves the server initiating the email delivery process to the recipient. Within the practice, the sending server contacts the recipient using the recipient server's IP address or domain name.
Once the email is received, the server forwards it to the MDA (Mail Delivery Agent). In this process, the email is stored and awaits the user to retrieve it.
The final step involves accessing and retrieving the email. In this step, the email stored in the MDA can be retrieved using the MUA.
However, recipients can also retrieve messages through the POP3 or IMAP protocols, allowing access to messages from various devices.
Setting up Simple Mail Transfer Protocol on various platforms fundamentally follows similar principles. Here's a general guide for configuring it on several different platforms:
First, you can send emails from your website using a chosen server. Accordingly, follow these steps to configure this protocol in WordPress:
If you're using native PHP scripts without a specific framework, you can send emails using external libraries like PHPMailer.
Here is a basic outline for a native PHP script:
<?php include "classes/class.phpmailer.php"; $mail = new PHPMailer; $mail->IsSMTP(); $mail->SMTPSecure = 'ssl'; $mail->Host = "localhost"; //Replace with your email provider's hostname $mail->SMTPDebug = 2; $mail->Port = 465; $mail->SMTPAuth = true; $mail->Timeout = 60; // Sending timeout (in seconds) $mail->SMTPKeepAlive = true; $mail->Username = "admin@yourdomain"; //your email user $mail->Password = "XXXXX"; //Youremailpassword $mail->SetFrom("admin@yourdomain","Sender namel"); //Set sender email $mail->Subject = "Email Notification from Website"; //Email subject $mail->AddAddress("admin@yourdomain","Recipient Name"); //Recipient email $mail->MsgHTML("Email Sent from Website"); if($mail->Send()) { echo "Message has been sent"; }else { echo "Failed to send the message"; } ?> |
Note: Please replace "localhost", "admin@yourdomain", "XXXXX", and other placeholders with your actual email server details.
Here's an example setup using PHPMailer:
CodeIgniter is a popular PHP framework. Configuring Simple Mail Transfer Protocol in this framework involves modifying configuration files. Here's an overview of the CodeIgniter script:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; class Welcome extends CI_Controller { public function __construct() { parent::__construct(); require APPPATH.'libraries/phpmailer/src/Exception.php'; require APPPATH.'libraries/phpmailer/src/PHPMailer.php'; require APPPATH.'libraries/phpmailer/src/SMTP.php'; } function index() { // PHPMailer object $response = false; $mail = new PHPMailer(); // SMTP configuration $mail->isSMTP(); $mail->Host = 'hostdomain.com'; //adjust according to the hosting/server domain used $mail->SMTPAuth = true; $mail->Username = '[email protected]'; // user email $mail->Password = 'xxxxxxxxxx'; // email password $mail->SMTPSecure = 'ssl'; $mail->Port = 465; $mail->Timeout = 60; // sending timeout (dalam detik) $mail->SMTPKeepAlive = true; $mail->setFrom('[email protected]', ''); // user email $mail->addReplyTo('[email protected]', ''); //user email // Add a recipient $mail->addAddress('[email protected]'); //recipient email // Email subject $mail->Subject = 'SMTP Codeigniter'; // email subject // Set email format to HTML $mail->isHTML(true); // Email body content $mailContent = "<h1>SMTP Codeigniterr</h1> <p>Laporan email SMTP Codeigniter.</p>"; // email content $mail->Body = $mailContent; // Send email if(!$mail->send()){ echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; }else{ echo 'Message has been sent'; } } } |
As to make these changes, follow these steps:
WDYT, you like my article?