What is the purpose of using the mail() function in PHP?
The mail() function in PHP is used to send emails from a web server. It is commonly used to send notifications, alerts, or messages to users. By using the mail() function, you can easily incorporate email functionality into your PHP scripts.
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email sent using the mail() function in PHP.";
$headers = "From: sender@example.com";
// Send email
$mailSent = mail($to, $subject, $message, $headers);
if($mailSent){
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}
Keywords
Related Questions
- What function in PHP can be used to read the contents of an external file, such as file_get_contents?
- What is the best practice for allowing users to delete specific content on a PHP forum without compromising security?
- How can PHP be used to manipulate and analyze uploaded images in an xt-commerce Shop-System?