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:

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

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

In this example, replace with the email address of the recipient, and 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.

Notify of
Inline Feedbacks
View all comments