Yii Framework Forum: Envío de E-mails con email extension - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Envío de E-mails con email extension Rate Topic: -----

#1 User is offline   makita 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 30-December 10

  Posted 19 January 2011 - 10:52 AM

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.
*
* @author Jonah Turnquist <poppitypop@gmail.com>
* @link http://php-thoughts.cubedwater.com/
* @version 1.0
*/
class Email extends CApplicationComponent {
/**
* @var string Type of email. Options include "text/html" and "text/plain"
*/
public $type = 'text/html';
/**
* @var string Receiver, or receivers of the mail.
*/
public $to = null;

/**
* @var string Email subject
*/
public $subject = 'prueba';

/**
* @var string from address
*/
public $from = 'test1@gmail.com';

/**
* @var string Reply-to address
*/
public $replyTo = 'test1@gmail.com';

/**
* @var string Return-path address
*/
public $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 $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 $bcc = null;

/**
* @var string Main content
*/
public $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 $delivery = 'php';

/**
* @var string language to encode the message in (eg "Japanese", "ja", "English", "en" and "uni" (UTF-8))
*/
public $language= 'uni';

/**
* @var string the content-type of the email
*/
public $contentType= 'utf-8';

/**
* @var string The view to use as the content of the email, as an alternative to setting $this->message.
* Must be located in application.views.email directory. This email object is availiable within the view
* through $email, thus letting you define things such as the subject within the view (helps maintain
* seperation of logic and output).
*/
public $view = null;

/**
* @var array Variable to be sent to the view.
*/
public $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 $layout = null;

/**
* @var integer line length of email as per RFC2822 Section 2.1.1
*/
public $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 $this->message instead for the content of the email
*/
public function send($arg1=null) {
if ($this->view !== null) {
if ($arg1 == null)
$vars = $this->viewVars;
else
$vars = $arg1;

$view = Yii::app()->controller->renderPartial('application.views.email.'.$this->view, array_merge($vars, array('email'=>$this)), true);
if ($this->layout === null) {
$message = $view;
} else {
$message = Yii::app()->controller->renderPartial('application.views.email.layouts.'.$this->layout, array('content'=>$view), true);
}
} else {
if ($arg1 === null) {
$message = $this->message;
} else {
$message = $arg1;
}
}

//process 'to' attribute
$to = $this->processAddresses($this->to);
return $this->mail($to, $this->subject, $message);
}

private function mail($to, $subject, $message) {
switch ($this->delivery) {
case 'php':
$message = wordwrap($message, $this->lineLength);
mb_language($this->language);
return mb_send_mail($to, $subject, $message, implode("\r\n", $this->createHeaders()));
case 'debug':
$debug = Yii::app()->controller->renderPartial('email.debug',
array_merge(compact('to', 'subject', 'message'), array('headers'=>$this->createHeaders())),
true);
Yii::app()->user->setFlash('email', $debug);
break;
}
}
private function createHeaders() {
$headers = array();

//maps class variable names to header names
$map = array(
'from' => 'From',
'cc' => 'Cc',
'bcc' => 'Bcc',
'replyTo' => 'Reply-To',
'returnPath' => 'Return-Path',
);
foreach ($map as $key => $value) {
if (isset($this->$key))
$headers[] = "$value: {$this->processAddresses($this->$key)}";
}
$headers[] = "Content-Type: {$this->type}; charset=".$this->contentType;
$headers[] = "MIME-Version: 1.0";

return $headers;
}
private function processAddresses($addresses) {
return (is_array($addresses)) ? implode(', ', $addresses) : $addresses;
}
}



Si alguien me puede decir que me falta para que funcione el plugin lo agradecería
SAludos! =)
0

#2 User is offline   Jack Fiallos 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 256
  • Joined: 15-October 09
  • Location:Mexico

Posted 19 January 2011 - 11:02 AM

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
Celestic Dev Team
Yii Open Source Project Manager
0

#3 User is offline   makita 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 30-December 10

Posted 19 January 2011 - 11:29 AM

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 :/
0

#4 User is offline   ClaCS 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 21-January 11

Posted 03 March 2011 - 04:19 PM

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
0

#5 User is offline   awp.black.69 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 24-February 13

Posted 24 February 2013 - 12:32 PM

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 !!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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