Source code for sending an email using PHP

April 28, 2023

Here’s a basic example of sending an email using PHP’s mail() function:

<?php
$to = 'recipient@example.com';
$subject = 'Test Email';
$message = 'This is a test email.';
$headers = 'From: sender@example.com' . "\r\n" .
    'Reply-To: sender@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

In this example, replace recipient@example.com with the email address of the recipient, and sender@example.com with the email address of the sender. You can also customize the subject and message to your needs.

Note that the mail() function relies on your server’s configuration to send email. If you encounter issues, you may need to check with your hosting provider or system administrator. Additionally, using mail() function can be subject to abuse and spamming, so it’s important to use it responsibly and securely.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments