use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); // enable exceptions try { //Server settings $mail->SMTPDebug = 0; // SMTP debugging (0 = no debugging) $mail->isSMTP(); $mail->Host = 'smtp.example.com'; $mail->SMTPAuth = true; $mail->Username = 'yourusername@example.com'; $mail->Password = 'yourpassword'; $mail->SMTPSecure = 'tls'; // tls or ssl $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('sender@example.com', 'Sender Name'); $mail->addAddress('recipient@example.com', 'Recipient Name'); $mail->addReplyTo('sender@example.com', 'Sender Name'); //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Test Email Subject'; $mail->Body = 'Test Email Body
'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent. Error: ', $mail->ErrorInfo; }
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); // enable exceptions try { //Recipients $mail->setFrom('sender@example.com', 'Sender Name'); $mail->addAddress('recipient@example.com', 'Recipient Name'); $mail->addReplyTo('sender@example.com', 'Sender Name'); //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Test Email Subject'; $mail->Body = 'In this example, we are using PHP's mail() function to send the email message. We set our message recipients and content, including an alternative plaintext version of the email for non-HTML mail clients. PHPMailer is a package library that can be installed using Composer. The Github repository for PHPMailer can be found at https://github.com/PHPMailer/PHPMailer.Test Email Body
'; $mail->AltBody = 'This is the plain text version of the email content for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent. Error: ', $mail->ErrorInfo; }