phpmailerHow can I use PHPMailer with XAMPP on Windows?
PHPMailer is an open-source library for sending emails through PHP code. It can be used with XAMPP on Windows to send emails from a local development environment. Here is an example of how to use PHPMailer with XAMPP on Windows:
// Require PHPMailer library
require_once('path/to/PHPMailer/PHPMailerAutoload.php');
// Create an instance of PHPMailer
$mail = new PHPMailer();
// Set SMTP configuration
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Set email content
$mail->setFrom('[email protected]', 'From Name');
$mail->addAddress('[email protected]', 'To Name');
$mail->Subject = 'PHPMailer on XAMPP';
$mail->Body = 'This is a test email sent using PHPMailer on XAMPP.';
// Send email
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Output example
Message has been sent
Code explanation
- Require PHPMailer library - includes the PHPMailer library from the specified path.
- Create an instance of PHPMailer - creates a new instance of the PHPMailer class.
- Set SMTP configuration - sets the SMTP configuration for the email.
- Set email content - sets the from address, to address, subject and body of the email.
- Send email - sends the email.
Helpful links
More of Phpmailer
- How can I configure PHPMailer to support Polish characters?
- How do I use PHPMailer to attach a ZIP file?
- How can I use PHPMailer in Yii 1?
- How do I determine which version of PHPMailer I'm using?
- How can I use PHPMailer without SMTP secure?
- How can I configure PHPMailer to work with GoDaddy?
- How do I configure PHPmailer to use Zoho SMTP?
- How can I use PHPMailer to send emails with a Yahoo account?
- How do I use PHPMailer to encode emails in UTF-8?
- How do I set the X-Mailer header using PHPMailer?
See more codes...