我認爲你缺少端口,在你的代碼的主機信息,除非你沒有展示你的整個代碼,請參閱例如here
public function actionViewTest() {
// Render view and get content
// Notice the last argument being `true` on render()
$content = $this->render('viewTest', array(
'Test' => 'TestText 123',
), true);
// Plain text content
$plainTextContent = "This is my Plain Text Content for those with cheap emailclients ;-)\nThis is my second row of text";
// Get mailer
$SM = Yii::app()->swiftMailer;
// Get config
$mailHost = 'mail.example.com';
$mailPort = 25; // Optional
// New transport
$Transport = $SM->smtpTransport($mailHost, $mailPort);
// Mailer
$Mailer = $SM->mailer($Transport);
// New message
$Message = $SM
->newMessage('My subject')
->setFrom(array('[email protected]' => 'Example Name'))
->setTo(array('[email protected]' => 'Recipient Name'))
->addPart($content, 'text/html')
->setBody($plainTextContent);
// Send mail
$result = $Mailer->send($Message);
}
如果你的主機是在Gmail ,將端口設置爲587或465
$mail->Port = 587; or $mail->Port = 465;
here是一個幾乎類似於你的問題的問題
如果你在這裏添加你的代碼會更好,你在你的控制器發送郵件的動作中寫的是什麼,以及你的處理你的驗證碼的方式 –
captcha我使用了ccaptcha驗證警予 –