Yii Framework Forum: Sending Email - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Sending Email Gmail smtp server Rate Topic: *---- 1 Votes

#1 User is offline   Leonardo Montenegro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 05-October 10
  • Location:Nil√≥polis - RJ

Posted 20 December 2010 - 02:20 PM

Friends,

I am trying to use this extension to send emails::
http://www.yiiframew.../extension/mail

I am using Gmail as smtp server.
I tryed this conf. at main.php:
'mail' => array(
   'class' => 'ext.mail.YiiMail',
   'transportType' => 'php',
   'transportOptions'=>array(
          'host'=>'smtp.gmail.com',
          'port_secure'=>true,
          'enc_tls'=>true,
          'username'=>'XXXXXXX',
          'password'=>'XXXXXXX',
          'port'=>587,
    ),
    'viewPath' => 'application.views.mail',
    'logging' => true,
    'dryRun' => false


and this is the controller code i am trying to use:

                $emailEnvio = New YiiMailMessage;
                $emailEnvio->view = 'emailEnvioDeArquivo';
                $emailEnvio->setBody();
                $emailEnvio->from = "XXXXXX@XXXXXXXX.XXX";

                $emailContato = emailContato::model()->findAllByAttributes(array('id_email'=>$email->id));
                if(!empty($emailContato)){
                    foreach($emailContato as $ec){
                        $endereco = Pagamarela::model()->findByPk($ec->id_pagamarela);
                        Yii::log($endereco->email, 'info', 'email');
                        $emailEnvio->addBcc($endereco->email);
                    }
                }
                Yii::app()->mail->send($emailEnvio);

I received this error:
mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at &quot;localhost&quot; port 25, verify your &quot;SMTP&quot; and &quot;smtp_port&quot; setting in php.ini or use ini_set()

Help please.
Always Learning
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 20 December 2010 - 02:58 PM

You need to set the transport type to 'smtp' :)

'php' is local sendmail.
"Less noise - more signal"
0

#3 User is offline   Leonardo Montenegro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 67
  • Joined: 05-October 10
  • Location:Nil√≥polis - RJ

Posted 20 December 2010 - 03:53 PM

View Postjacmoe, on 20 December 2010 - 02:58 PM, said:

You need to set the transport type to 'smtp' :)

'php' is local sendmail.


For sure!
And put this on main.php:
'encryption'=>'tls',
with
'port'=>465,
instend of
'port'=>587,
Always Learning
0

#4 Guest_sidebar_*

  • Group: Guests

Posted 31 December 2010 - 09:41 AM

Not sure if this is answered, but I came across the same problem with our hosted smtp server.Following trick helped me to solve this problem.

I have created a simple mail form and tested the configurations.

<html>
<body>

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name="senders name";
$myemail="senders email address";
$toemail = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$header = "From: ". $name . " <" . $myemail . ">\r\n";
ini_set('sendmail_from', 'admin@yourdomain.com'); <==this line is making the difference.
mail( $toemail, "Subject: $subject", $message, $header);
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>

</body>
</html>

I will also create a new tips topic to help any future users. Hope this helps. Good luck!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users