dede
dede

Reputation: 831

The from address failed :Called Mail() without being connected

I want to send email from localhost using SMTP mail in Yii Framework. I am already copying PhpMailer into extensions folder. I am following the tutorial to setting the main.php like below

'components'=>array(

    'Smtpmail'=>array(
        'class'=>'application.extensions.smtpmail.PHPMailer',
        'Host'=>"smtp.gmail.com",
        'Username'=>'[email protected]',
        'Password'=>'myPassword',
        'Mailer'=>'smtp',
        'Port'=>465,
        'SMTPAuth'=>true, 
        'SMTPSecure' => 'ssl'
    ),

Then, in my controller :

            $mail=Yii::app()->Smtpmail;
            $mail->SetFrom('[email protected]', 'My Name');
            $mail->Subject= $subject;
            $mail->MsgHTML($email);
            $mail->AddAddress($to, "");

The browser give me an error : The following From address failed: [email protected] : Called Mail() without being connected. What is wrong with that?

Upvotes: 2

Views: 1460

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

for smtp.gmail.com try using 587 for port and tls for SMTPsecure

'Smtpmail'=>array(
    'class'=>'application.extensions.smtpmail.PHPMailer',
    'Host'=>"smtp.gmail.com",
    'Username'=>'[email protected]',
    'Password'=>'myPassword',
    'Mailer'=>'smtp',
    'Port'=>'587',    // or 587
    //'SMTPAuth'=>true, 
    'SMTPAuth'=>false, 
    'SMTPSecure' => 'tls'
),

,

Upvotes: 1

Related Questions