W3school php mail

W3Schools provides a simple example of how to send an email using PHP. Here is the code:

<?php
$to = "[email protected]";
$subject = "Test email from W3Schools";
$message = "Hello! This is a test email sent from W3Schools.";
$headers = "From: [email protected]";

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

Let's break down what each line does:

  1. $to = "[email protected]";: This sets the recipient's email address.
  2. $subject = "Test email from W3Schools";: This sets the subject of the email.
  3. $message = "Hello! This is a test email sent from W3Schools.";: This sets the body of the email.
  4. $headers = "From: [email protected]";: This sets the "From" header of the email. This is the email address that will appear in the recipient's email client.
  5. mail($to, $subject, $message, $headers);: This sends the email using the mail() function. The arguments are:
    • $to: The recipient's email address.
    • $subject: The subject of the email.
    • $message: The body of the email.
    • $headers: The headers of the email.

Note that this is a very basic example, and you may want to add more functionality to your email script, such as:

Also, keep in mind that the mail() function is not always reliable, and you may need to use a more advanced method of sending emails, such as using a PHP mail library or a third-party API.