How can the PHP-Mailer class improve the process of sending HTML emails in PHP?
Sending HTML emails in PHP can be a cumbersome process due to the need to format the email content properly. The PHP-Mailer class simplifies this process by providing a convenient way to send HTML emails with attachments, inline images, and custom headers.
<?php
require 'PHPMailer/PHPMailer.php';
// Create a new PHPMailer instance
$mail = new PHPMailer();
// Set the email content type to HTML
$mail->isHTML(true);
// Set the email subject and body
$mail->Subject = 'Example HTML Email';
$mail->Body = '<h1>Hello, world!</h1>';
// Set the sender and recipient
$mail->setFrom('sender@example.com', 'Sender Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
// Send the email
if($mail->send()) {
echo 'Email sent successfully';
} else {
echo 'Email sending failed';
}
Keywords
Related Questions
- How can you ensure that data retrieved from one MySQL database and inserted into another in PHP maintains its correct character encoding?
- How can users specify a desired time range for displaying values in a PHP page using jpGraph with a SQLite database?
- How can one ensure that the URL variable is properly concatenated and formatted in header(Location: URL) in PHP?