Envío de E-mails con email extension

Hola, estoy tratando de hacer el envío de mails usando la extension email

He seguido todos los pasos antes mencionados , pero a pesar de que no arroja ningún error, no se envía el correo.

adjuntos los códigos:

EN config/main.php

‘email’=>array(

                    'class'=>'application.extensions.email.Email',


                    'delivery'=>'debug',


            ),

en el controlador de mi aplicacion

$this->widget(‘application.extensions.email.Debug’);

                    $email=Yii::app()->email;


                    $email->to="test2@gmail.com";


                    $email->subject="holiii";


                    $email->message="prueba";


                    $email->send();

y por último en el archivo de mi extension en extension/email/email.php

<?php

/**

  • Email class file.

*/

class Email extends CApplicationComponent {

    /**


     * @var string Type of email.  Options include &quot;text/html&quot; and &quot;text/plain&quot;


     */


    public &#036;type = 'text/html';


    /**


     * @var string Receiver, or receivers of the mail.


     */


    public &#036;to = null;


    


    /**


     * @var string Email subject


     */


    public &#036;subject = 'prueba';


    


    /**


     * @var string from address


     */


    public &#036;from = 'test1@gmail.com';


    


    /**


     * @var string Reply-to address


     */


    public &#036;replyTo = 'test1@gmail.com';


    


    /**


     * @var string Return-path address


     */


    public &#036;returnPath = null;


    


    /**


     * @var string Carbon Copy


     *


     * List of email's that should receive a copy of the email.


     * The Recipient WILL be able to see this list


     */


    public &#036;cc = null;





    /**


     * @var string Blind Carbon Copy


     *


     * List of email's that should receive a copy of the email.


     * The Recipient WILL NOT be able to see this list


     */


    public &#036;bcc = null;


    


    /**


     * @var string Main content


     */


    public &#036;message = 'se ha subido un video';


    


    /**


     * @var string Delivery type.  If set to 'php' it will use php's mail() function, and if set to 'debug'


     * it will not actually send it but output it to the screen


     */


    public &#036;delivery = 'php';


    


    /**


     * @var string language to encode the message in (eg &quot;Japanese&quot;, &quot;ja&quot;, &quot;English&quot;, &quot;en&quot; and &quot;uni&quot; (UTF-<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />)


     */


    public &#036;language= 'uni';


    


    /**


     * @var string the content-type of the email


     */


    public &#036;contentType= 'utf-8';


    


    /**


     * @var string The view to use as the content of the email, as an alternative to setting &#036;this-&gt;message.


     * Must be located in application.views.email directory.  This email object is availiable within the view


     * through &#036;email, thus letting you define things such as the subject within the view (helps maintain 


     * seperation of logic and output).


     */


    public &#036;view = null;


    


    /**


     * @var array Variable to be sent to the view.


     */


    public &#036;viewVars = null;        


    


    /**


     * @var string The layout for the view to be imbedded in. Must be located in


     * application.views.email.layouts directory.  Not required even if you are using a view


     */


    public &#036;layout = null;


    


    /**


     * @var integer line length of email as per RFC2822 Section 2.1.1


     */


    public &#036;lineLength = 70;


    


    public function __construct() {


            Yii::setPathOfAlias('email', dirname(__FILE__).'/views');


    }


    


    /**


     * Sends email.


     * @param mixed the content of the email, or variables to be sent to the view.


     * If not set, it will use &#036;this-&gt;message instead for the content of the email


     */


    public function send(&#036;arg1=null) {


            if (&#036;this-&gt;view &#33;== null) {


                    if (&#036;arg1 == null)


                            &#036;vars = &#036;this-&gt;viewVars;


                    else


                            &#036;vars = &#036;arg1;


                    


                    &#036;view = Yii::app()-&gt;controller-&gt;renderPartial('application.views.email.'.&#036;this-&gt;view, array_merge(&#036;vars, array('email'=&gt;&#036;this)), true);


                    if (&#036;this-&gt;layout === null) {


                            &#036;message = &#036;view;


                    } else {


                            &#036;message = Yii::app()-&gt;controller-&gt;renderPartial('application.views.email.layouts.'.&#036;this-&gt;layout, array('content'=&gt;&#036;view), true);


                    }


            } else {


                    if (&#036;arg1 === null) {


                            &#036;message = &#036;this-&gt;message;


                    } else {


                            &#036;message = &#036;arg1;


                    }


            }





            //process 'to' attribute


            &#036;to = &#036;this-&gt;processAddresses(&#036;this-&gt;to);


            return &#036;this-&gt;mail(&#036;to, &#036;this-&gt;subject, &#036;message);


    }


    


    private function mail(&#036;to, &#036;subject, &#036;message) {


            switch (&#036;this-&gt;delivery) {


                    case 'php':


                            &#036;message = wordwrap(&#036;message, &#036;this-&gt;lineLength);


                            mb_language(&#036;this-&gt;language);


                            return mb_send_mail(&#036;to, &#036;subject, &#036;message, implode(&quot;&#092;r&#092;n&quot;, &#036;this-&gt;createHeaders()));


                    case 'debug':


                            &#036;debug = Yii::app()-&gt;controller-&gt;renderPartial('email.debug',


                                            array_merge(compact('to', 'subject', 'message'), array('headers'=&gt;&#036;this-&gt;createHeaders())),


                                            true);


                            Yii::app()-&gt;user-&gt;setFlash('email', &#036;debug);


                            break;


            }


    }


    private function createHeaders() {


            &#036;headers = array();


            


            //maps class variable names to header names


            &#036;map = array(


                    'from' =&gt; 'From',


                    'cc' =&gt; 'Cc',


                    'bcc' =&gt; 'Bcc',


                    'replyTo' =&gt; 'Reply-To',


                    'returnPath' =&gt; 'Return-Path',


            );


            foreach (&#036;map as &#036;key =&gt; &#036;value) {


                    if (isset(&#036;this-&gt;&#036;key))


                            &#036;headers[] = &quot;&#036;value: {&#036;this-&gt;processAddresses(&#036;this-&gt;&#036;key)}&quot;;


            }


            &#036;headers[] = &quot;Content-Type: {&#036;this-&gt;type}; charset=&quot;.&#036;this-&gt;contentType;


            &#036;headers[] = &quot;MIME-Version: 1.0&quot;;


            


            return &#036;headers;


    }


    private function processAddresses(&#036;addresses) {


            return (is_array(&#036;addresses)) ? implode(', ', &#036;addresses) : &#036;addresses;


    }

}

Si alguien me puede decir que me falta para que funcione el plugin lo agradecería

SAludos! =)

estas en local o en servidor ??

tienes habilitado algun servidor para enviar correos ??

revisaste si el puerto 110 smtp esta habilitado o si utilizas algun otro puerto ??

La verdad no he utilizado esa extension, pero por lo que veo debe de hacer uso de la fx mb_send_mail, por ahi veo que tienes la variable ‘delivery’=>‘debug’, y segun la documentacion del metodo eso no enviara el metodo, solamente lo mostrara en pantalla… debes de utilizar ‘delivery’=>‘php’, para poder enviarlo

HOla, estoy en local y ya he cambiado debug por php y no pasa nada. revisé el puerto 110 y está activo.

la verdad no sé que podrá ser :confused:

Hola

Yo tb estuve unos dias indagando sobre la forma de enviar un mail y lo logre :), para lo cual utilice la extension del siguiente post

Tenes q tener en cuenta q tb debes habilitar la extension openssl del php.ini de tu servidor; especificamente descomentar la linea extension=php_openssl.dll y reiniciar tu servidor. Ojo que las pruebas las hice para enviar desde una cuenta gmail corporativa

Las configuraciones en el config/main.php son las siguientes:


'import' => array(

        ...

        'ext.yii-mail.YiiMailMessage',

    ),

...

'components' => array(

        'mail' => array(

            'class' => 'ext.yii-mail.YiiMail',

            'transportType' => 'smtp',

            'transportOptions' => array(

                'host' => 'smtp.gmail.com',

                'encryption' => 'ssl',

                'username' => 'micorreo@miempresa.com',

                'password' => 'xxx',

                'port' => 465,

            ),

            'viewPath' => 'application.views.mails',

        ),

...

y en tu controlador podes poner


public function actionEnviarMail() {

        

        $message = new YiiMailMessage;        

        

        $message->subject = 'My Subject';

        $message->view ='prueba';//nombre de la vista q conformara el mail

        $message->setBody('','text/html');//codificar el html de la vista

        $message->from =('micorreo@miempresa.com'); // alias del q envia

        $message->setTo('tucorreo@hotmail.com'); // a quien se le envia

        

        Yii::app()->mail->send($message);

	}

cualquier problema nos avisas ;)

Salu2

Hey…

I want to sent inline image in mail. I dont want to use img tag which would point to some public accessible image. I know it cant be done by using multipart/mixed content type instead of using text/html but dont know how to do that in YiiMailMessage.

Can somebody help !!