$to = 'example@email.com'; $subject = 'Test email'; $message = 'This is a test email.'; $headers = 'From: ' . $to; mail($to, $subject, $message, $headers);
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'vendor/autoload.php'; $mail = new PHPMailer(true); $to = 'example@email.com'; try { $mail->setFrom($to); $mail->addAddress($to); $mail->Subject = 'Test email'; $mail->Body = 'This is a test email.'; $mail->send(); } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }In these examples, the PHP script is sending an email to the same email address that is set as the "To" and "From" address. The first example is using the built-in mail() function, while the second example is using the PHPMailer library. The PHPMailer library is a popular package for sending emails in PHP, and it provides additional features and options compared to the basic mail() function.