1

I want to try sending email of my web application from localhost. I am using SMTP Gmail. I am installing to my computer an SMTP server to send out mail with this one. My syntax in my controller like below:

Yii::import('application.extensions.PHPMailer.JPhpMailer');
        $mail = new JPhpMailer;
        $mail->IsSMTP();
        $mail->Host = 'smpt.gmail.com:';
        $mail->Posrt = 587;
        $mail->SMTPSecure = 'tls'; 
        $mail->SMTPAuth = true;
        $mail->Username = 'myGmailAccount';
        $mail->Password = 'myPassword';
        $mail->SetFrom('$to', '$name');
        $mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
        $mail->MsgHTML('<h1>JUST A TEST!</h1>');
        //$mail->AddAddress('');
        $mail->Send();

But an error happen :

SMTP -> ERROR: Failed to connect to server: The requested address is not valid in its context. (10049) SMTP Error: Could not connect to SMTP host.

How to fix it?

dede
  • 823
  • 4
  • 13
  • 24

1 Answers1

1

There's a very basic error here:

$mail->Host = 'smpt.gmail.com:';

Should be:

$mail->Host = 'smtp.gmail.com';

It also looks like you're using an old version of PHPMailer, so get the latest, and it would probably help to read the docs about sending via gmail.

Synchro
  • 35,538
  • 15
  • 81
  • 104