$to = "recipient@example.com"; $subject = "Testing PHP Mail"; $message = "This is a test mail sent using PHP mail() function."; $headers = "From: sender@example.com\r\nReply-To: sender@example.com"; mail($to, $subject, $message, $headers);
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 0; $mail->isSMTP(); $mail->Host = 'smtp.example.com'; $mail->SMTPAuth = true; $mail->Username = 'email@example.com'; $mail->Password = 'password'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; //Recipients $mail->setFrom('email@example.com', 'Sender Name'); $mail->addAddress('recipient@example.com', 'Recipient Name'); //Content $mail->isHTML(true); $mail->Subject = 'Testing PHPMailer'; $mail->Body = 'This example uses PHPMailer to send an email with SMTP authentication. The SMTP server details and authentication credentials are specified in the code. The email content is in HTML format, and the email address of the sender and recipient are specified in the code. The example includes error handling to display any errors that may occur during the email sending process.This is a test email sent using PHPMailer.
'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Error: {$mail->ErrorInfo}"; }