W3docs

Send email with a template using php

To send an email using PHP, you can use the "mail()" function.

To send an email using PHP, you can use the "mail()" function. Here is an example of a basic email template:

Example of sending an email with the mail() function in PHP

<?php
$to = "[email protected]";
$subject = "Test Email";
$message = "This is a test email sent using PHP.";
$headers = "From: Sender \<[email protected]\>\r\n";
mail($to, $subject, $message, $headers);
?>

<div class="alert alert-info flex not-prose">Watch a course <span class="hidden md:block">Watch a video course</span> Learn object oriented PHP </div>

In this example, an email is sent to the address "<[email protected]>" with the subject "Test Email" and the message text "This is a test email sent using PHP." The "From" header is set to "Sender <[email protected]>".

Note: The mail() function uses the local Mail Transfer Agent (MTA) on the server where the PHP script is running to send the email. Therefore, a configured MTA must be present on the server for the email to be sent successfully.