mail php code

To send an email using PHP, you can use the mail() function. This function requires at least three parameters: the recipient’s email address, the subject of the email, and the message body.

Here’s an example of how you can use the mail() function to send an email:

<?php

$to = '[email protected]';
$subject = 'Email Subject';
$message = 'This is the message body of the email';
$headers = 'From: [email protected]' . "\r\n" .
           'Reply-To: [email protected]' . "\r\n" .
           'X-Mailer: PHP/' . phpversion();

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

?>

This code will send an email to [email protected] with the subject 'Email Subject' and the message body 'This is the message body of the email'. The $headers variable includes additional information about the sender and the email client used to send the message.

Note that the mail() function may not work on all servers, and you may need to configure your server and/or PHP installation to use it properly. It is also recommended to use a more robust email library like PHPMailer for more advanced email functionality.

Leave a Comment