9951 explained code solutions for 126 technologies

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:

  1. Download the PHPMailer library from GitHub.

  2. Extract the library to protected/vendors/phpmailer/ in your Yii 1 application.

  3. Add the PHPMailer library to your application's autoloader:

  1. 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';
  1. 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';
  1. Send the email:
if ($mail->send()) {
    echo 'Email sent successfully!';
} else {
    echo 'Error sending email: ' . $mail->ErrorInfo;
  1. Optionally, you can add attachments to the email:

Helpful links

Edit this code on GitHub