To send an email with PHP, you can use the built-in `mail()` function. Here’s an example of the code to send a simple email:
“`php
$to = “recipient@example.com”;
$subject = “Test Email”;
$message = “This is a test email.”;
$headers = “From: sender@example.com”;
if (mail($to, $subject, $message, $headers)) {
echo “Email sent successfully.”;
} else {
echo “Failed to send email.”;
}
“`
In the code above, 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 fit your needs.
The `mail()` function takes four parameters: the recipient’s email address, the subject of the email, the message content, and the additional headers. In this example, we have only provided the `From` header.
It’s important to note that the `mail()` function uses the server’s default email configuration to send the email. To customize the email settings, such as using SMTP or specifying a mail server, you might need to use a library like PHPMailer or SwiftMailer.