phpmailerHow do I use PHPMailer to send emails through Namecheap?
PHPMailer is an open source library for sending emails in PHP. To use PHPMailer to send emails through Namecheap, you will need to:
- Install PHPMailer using Composer, the PHP package manager:
composer require phpmailer/phpmailer
- Create a new PHPMailer instance with your Namecheap credentials:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.namecheap.com';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
- Set the sender and recipient addresses:
$mail->setFrom('[email protected]', 'John Doe');
$mail->addAddress('[email protected]', 'Jane Doe');
- Set the subject and body of the email:
$mail->Subject = 'Hello';
$mail->Body = 'This is a test message.';
- Send the email:
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
- Output:
Message has been sent
For more information, see the PHPMailer documentation and the Namecheap SMTP setup guide.
More of Phpmailer
- How do I configure PHPmailer to use Zoho SMTP?
- How do I use PHPMailer to attach a ZIP file?
- How can I configure PHPMailer to support Polish characters?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer with Yii2?
- How do I set the X-Mailer header using PHPMailer?
- How can I use PHPMailer without SMTP secure?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I determine which version of PHPMailer I'm using?
- How can I send a UTF-8 encoded email using PHPMailer?
See more codes...