How do you send emails from a PHP script

Sending emails through a PHP script can be achieved using the built-in `mail()` function. This function allows you to send both plain text and HTML emails to recipients.

Example of Sending Email Using PHP

<?php $to = 'recipient@example.com'; $subject = 'Test Email'; $message = 'Hello, this is a test email!'; $headers = 'From: sender@example.com' . "\r\n" . 'Reply-To: sender@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); // Sending the email if(mail($to, $subject, $message, $headers)) { echo 'Email sent successfully!'; } else { echo 'Email sending failed.'; } ?>

PHP email send email PHP mail function PHP PHP script email