How to send an email using PHP?

Spread the love

Sometimes, we want to send an email using PHP.

In this article, we’ll look at how to send an email using PHP.

How to send an email using PHP?

To send an email using PHP, we can use the mail function.

For instance, we write

<?php
$to = "nobody@example.com";
$subject = "subject";
$message = "hello";
$headers =
    "From: webmaster@example.com" .
    "\r\n" .
    "Reply-To: webmaster@example.com" .
    "\r\n" .
    "X-Mailer: PHP/" .
    phpversion();

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

to call mail with the $to email address, $subject emaiol subject, $message body, and the $headers email headers to send the email.

Conclusion

To send an email using PHP, we can use the mail function.

Leave a Reply

Your email address will not be published. Required fields are marked *