Send email php w3schools

Here is an example of how to send an email using PHP, based on the tutorial on W3Schools:

PHP Code:

<?php
// Define the email variables
$to = "[email protected]";
$subject = "Test Email";
$message = "This is a test email sent using PHP";
$headers = "From: [email protected]";

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

// Check if the email was sent successfully
if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully!";
} else {
    echo "Error sending email!";
}
?>

Explanation:

  1. The first line defines the recipient's email address ($to).
  2. The second line defines the subject of the email ($subject).
  3. The third line defines the message body of the email ($message).
  4. The fourth line defines the sender's email address ($headers) and sets the From header.
  5. The mail() function is used to send the email. It takes four arguments: the recipient's email address, the subject, the message body, and the headers.
  6. The if statement checks if the email was sent successfully. If it was, it echoes a success message. If not, it echoes an error message.

Note: This code assumes that your PHP script has permission to send emails. If you're running this code on a local machine, you may need to configure your email settings or use a third-party email service.

Also: This is a basic example, and you may want to add more features to your email sending script, such as: