Mail php html

A classic combination!

To send an email using PHP, you can use the mail() function, which is a built-in PHP function. Here's a basic example of how to use it:

<?php
  $to = '[email protected]';
  $subject = 'Test email';
  $message = 'This is a test email sent using PHP.';

  // Set the From header
  $from = '[email protected]';

  // Set the headers
  $headers = 'From: '. $from. "\r\n".
             'Reply-To: '. $from. "\r\n".
             'MIME-Version: 1.0'. "\r\n".
             'Content-Type: text/plain; charset=UTF-8';

  // Send the email
  mail($to, $subject, $message, $headers);
?>

In this example, we're sending an email to [email protected] with the subject "Test email" and a simple message. The From header is set to [email protected], and the headers variable is used to set the other headers.

Note that the mail() function returns a boolean value indicating whether the email was sent successfully or not. You can use this value to check if the email was sent correctly.

Here's a more advanced example that uses HTML in the email body:

<?php
  $to = '[email protected]';
  $subject = 'Test email with HTML';
  $message = '<html><body>This is a test email sent using PHP.</body></html>';

  // Set the From header
  $from = '[email protected]';

  // Set the headers
  $headers = 'From: '. $from. "\r\n".
             'Reply-To: '. $from. "\r\n".
             'MIME-Version: 1.0'. "\r\n".
             'Content-Type: text/html; charset=UTF-8';

  // Send the email
  mail($to, $subject, $message, $headers);
?>

In this example, we're sending an email with an HTML body. The Content-Type header is set to text/html to indicate that the email body contains HTML.

Keep in mind that the mail() function is a simple and basic way to send emails, and it may not work in all situations. For example, it may not work if your server has strict email sending restrictions or if the recipient's email provider blocks emails from your domain.

If you need more advanced email sending features, you may want to consider using a PHP email library or service, such as PHPMailer or SendGrid.