Ranjan
Ranjan

Reputation: 11

Not able to send mail using YiiMailer

I am trying to send a mail using YiiMailer Extension, when I used Port 465 getting error "fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host" and when I used port 587 its fails to send a mail.

Code: In controller:

            $mail = new YiiMailer();
            $mail->setData(array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form', 'mail' => $mail));
            $mail->setFrom('[email protected]', 'John Doe');
            $mail->setTo($_POST['UserLogin']['email']);
            $mail->setSubject('Reser Password');
            $mail->setBody('Simple message');
            $mail->IsSMTP();
            $mail->Host = "smtp.gmail.com";
            $mail->Port = 465;
            $mail->SMTPAuth = true;
            $mail->Username = "*******@gmail.com";
            $mail->Password = "********";
            if ($mail->send()) {
                Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
                Yii::log("Mail sent");
            } else {
                Yii::app()->user->setFlash('error','Error while sending email: '.$mail->getError());
                Yii::log("Mail Error");
            }
             }

In main.php

 'import'=>array(
    'application.models.*',
    'application.components.*',
            'ext.YiiMailer.YiiMailer',
),

Please help me to come out of this problem and I tried other extension too like Emailer, PHPMailer but there i got some SMTP error "smtp unable to connect to the remote server"

Thanks in advance

Upvotes: 0

Views: 3281

Answers (2)

Dency G B
Dency G B

Reputation: 8146

This works for me!

  $mail->IsSMTP();
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 587;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure= 'tls';
        $mail->Username = "*******@gmail.com";
        $mail->Password = "********";      

Upvotes: 1

aggelgian
aggelgian

Reputation: 351

I am guessing you do not have php_openssl enabled in your server's php.ini. Check phpinfo() to make sure you have it enabled.

Also you may need to add the lines

$mail->SMTPSecure='ssl';
$mail->Mailer='smtps';

Upvotes: 1

Related Questions