PHPMailer without SMTP
PHPMailer is a popular email sending library in PHP. By default, it uses SMTP (Simple Mail Transfer Protocol) to send emails. However, it also provides an option to send emails without using an SMTP server. This can be useful if you don’t have access to an SMTP server or if you prefer to use a different email sending method.
To use PHPMailer without SMTP, you can set the `isSMTP()` method to `false`. This tells PHPMailer to use the PHP `mail()` function instead of SMTP.
Example:
// Include PHPMailer library
require 'path/to/PHPMailer.php';
require 'path/to/SMTP.php'; // Only needed if using SMTP
// Create a new PHPMailer instance
$mailer = new PHPMailer\PHPMailer\PHPMailer();
// Set mailer to use PHP mail() function
$mailer->isSMTP(false);
// Set other email properties
$mailer->SetFrom("sender@example.com", "Sender Name");
$mailer->addAddress("recipient@example.com", "Recipient Name");
$mailer->Subject = "Test Email";
$mailer->Body = "This is a test email.";
// Send the email
if(!$mailer->send()) {
echo "Error sending email: " . $mailer->ErrorInfo;
} else {
echo "Email sent successfully!";
}
In this example, we first include the PHPMailer library and create a new instance of PHPMailer. Then, we set the `isSMTP()` method to `false` to tell PHPMailer to use the `mail()` function. After that, we set the email properties such as the sender, recipient, subject, and body. Finally, we call the `send()` method to send the email. If an error occurs, we print the error message using the `ErrorInfo` property of PHPMailer. Otherwise, we print a success message.