Sending email messages is a very common feature of a web application.Send Email using PHP
You can use the PHP mail()
function for creating and sending email messages to one or more recipients dynamically from your PHP application either in a plain-text form or formatted HTML.
Learn more about PHP Mail Function https://www.php.net/manual/en/function.mail.php
The Basic syntex of PHP Mail function is mail(to, subject, message, headers, parameters)
<?php // PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Base files require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; // create object of PHPMailer class with boolean parameter which sets/unsets exception. $mail = new PHPMailer(true); try { $mail->isSMTP(); // using SMTP protocol $mail->Host = 'smtp.gmail.com'; // SMTP host as gmail $mail->SMTPAuth = true; // enable smtp authentication $mail->Username = 'sender@gmail.com'; // sender gmail host $mail->Password = 'password'; // sender gmail host password $mail->SMTPSecure = 'tls'; // for encrypted connection $mail->Port = 587; // port for SMTP $mail->setFrom('sender@gmail.com', "Sender"); // sender's email and name $mail->addAddress('receiver@gmail.com', "Receiver"); // receiver's email and name $mail->Subject = 'Test subject'; $mail->Body = 'Test body'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { // handle error. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } ?>
Subscribe to My Programming YouTube Channel Before Downloading the code :
Read our More tutorials on PHP
Codeigniter 4 CRUD Operation With Ajax Example
Netflix clone app using Laravel
login form in React with Laravel