phpmailerHow can I use PHPMailer in Yii 1?
PHPMailer is a library for sending emails from PHP applications. It can be used with Yii 1 by following these steps:
-
Download the PHPMailer library from GitHub.
-
Extract the library to
protected/vendors/phpmailer/
in your Yii 1 application. -
Add the PHPMailer library to your application's autoloader:
Yii::import('application.vendors.phpmailer.*');
- Create an instance of the PHPMailer class and set the necessary properties (e.g.
Host
,Username
,Password
):
$mail = new PHPMailer();
$mail->Host = 'smtp.example.com';
$mail->Username = 'username';
$mail->Password = 'password';
- Set the recipient and message properties:
$mail->addAddress('[email protected]');
$mail->Subject = 'Test Email';
$mail->Body = 'This is a test email sent from Yii 1';
- Send the email:
if ($mail->send()) {
echo 'Email sent successfully!';
} else {
echo 'Error sending email: ' . $mail->ErrorInfo;
}
- Optionally, you can add attachments to the email:
$mail->addAttachment('/path/to/file.pdf');
Helpful links
More of Phpmailer
- How can I use PHPMailer with React?
- How can I configure PHPMailer to work with GoDaddy?
- How do I use PHPMailer to attach a ZIP file?
- How can I set up PHPMailer to use Zimbra SMTP?
- How can I configure PHPMailer to support Polish characters?
- How can I use PHPMailer to send emails from my WordPress site?
- How do I view the log for my PHPMailer emails?
- How do I use PHPMailer with IMAP?
- How do I check which version of PHPMailer I'm using?
See more codes...