Yii swift mailer not sending mail

187 views Asked by At

I am using yii mail swiftmailer extension to send mail .when am using this mail extension along with ccaptcha validation in the same form the mail is not sending.when it has be used alone without captcha validation it is sending email.i need to send email using this extension along with the ccaptcha validation in yii.

for email:

$subjek="verifymail";     
$from="[email protected]";
$getEmail="[email protected]";
$message= new YiiMailMessage;        
$message->subject=$subjek;       
$message->from=$from;
$message->setBody($activationlink, 'text/html');
$message->addTo($getEmail);  
Yii::app()->mail->send($message);
1

There are 1 answers

0
Eliethesaiyan On

I think you are missing port and host information in your code,unless you didnt show your whole code,see example 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);
}

If your host is gmail,put the port to 587 or 465

$mail->Port = 587; or $mail->Port = 465;

here is a question almost similar to your question