Yii Framework Forum: [EXTENSION] Mailer using PHPMailer - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] Mailer using PHPMailer Rate Topic: -----

#21 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 608
  • Joined: 08-May 09

Posted 09 June 2009 - 06:51 PM

Hi,
this is certainly a silly question:
I want to use a helper function or class to send an Email with Emailer extension, because I dont want to configure the mailer within the controller every time.
Where is the best place for it? How to extend the component extension correctly?

the function is something like this: function sendMail($to, $subject, $body){}
0

#22 User is offline   MetaYii 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 393
  • Joined: 07-October 08
  • Location:The Matrix

Posted 09 June 2009 - 08:13 PM

Quote

Hi,

this is certainly a silly question:

I want to use a helper function or class to send an Email with Emailer extension, because I dont want to configure the mailer within the controller every time.

Where is the best place for it? How to extend the component extension correctly?



the function is something like this: function sendMail($to, $subject, $body){}


You can find and example in the documentation tab of the extension.
0

#23 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 608
  • Joined: 08-May 09

Posted 10 June 2009 - 05:11 AM

this is my approach to configure the Emailer
  • create a class MyApp in protected/helpers folder
  • create a function MyApp::sendMail($to, $subject, $body)
  • import application/helpers.*
  • added the Emailer to application components

0

#24 User is offline   sn0rcha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 22-June 09

Posted 05 March 2010 - 03:17 AM

Anyone know how to get this to work with views in a theme?

Currently I have to copy the views to the views folder in the protected directory.

Cheers,
Sn0rcha
0

#25 User is offline   luis diego 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 02-February 10
  • Location:Costa Rica

Posted 11 June 2010 - 12:06 PM

Hello this extesion is amazing..
But How can I do to send a e-mail with images ?? I mean that the content of the e-mail contains images. (Not attachments).

I research and I need to specify some headers.. but using this extension how can I do that?
0

#26 User is offline   aqge 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 188
  • Joined: 02-September 10
  • Location:Indonesia

Posted 11 November 2010 - 01:34 AM


'components'=>array(
                'mailer' => array(
                          'class' => 'application.extensions.mailer.EMailer',
                          'pathViews' => 'application.views.email',
                          'pathLayouts' => 'application.views.layouts'
                       ),


this wont change the

   
protected $pathLayouts = 'application.views.email.layouts';


i ve to change it manualy on the emailer.php


is there any mistake?
Best Regard
Tidak ada coding yang salah
Yang ada hanyalah Coding yang lebih baik
0

#27 User is offline   psolovyov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-March 12

Posted 15 June 2012 - 06:14 PM

Hey guys, I'm trying to set up so Mailer works with the Godaddy account together. I have been so far unsuccessful. Can anybody let me know what is wrong in my configuration?

Yii::app()->mailer->Host = 'smtpout.secureserver.net';
		Yii::app()->mailer->IsSMTP(true);
		Yii::app()->mailer->Username = "info@****.com";
		Yii::app()->mailer->Password = "****";
		Yii::app()->mailer->From = 'info@****.com';
		Yii::app()->mailer->FromName = '****';
		Yii::app()->mailer->IsHTML(true);
		Yii::app()->mailer->CharSet = 'UTF-8';
		Yii::app()->mailer->AddReplyTo('info@****.com');
		Yii::app()->mailer->AddAddress($********->email);
		Yii::app()->mailer->Subject = '****';
		Yii::app()->mailer->Body = $message;
		if(!$mailer->Send())
		{
			$this->actionBad();
			throw new CHttpException(500, 'Something went horribly wrong');
		}
		else
		{
			$this->actionOk();			
		}


I get: "SMTP Error: Could not connect to SMTP host. Transaction Failed!"

I have enabled SMTP relay on the account and I still get this problem. :(


PS: one more question, is there a way of connecting with SSL using this extension?

EDIT:

Made it work - just had to put "relay-hosting.secureserver.net" into host part of the setup.

Continuing to work on SSL setup.

EDIT:

getting connection refused. I'm using 465 port, SMTPSecure = 'ssl' SMTPAuth = True.

This post has been edited by psolovyov: 15 June 2012 - 07:03 PM

0

#28 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 513
  • Joined: 08-August 09

Posted 15 June 2012 - 09:20 PM

View Postpsolovyov, on 15 June 2012 - 06:14 PM, said:

PS: one more question, is there a way of connecting with SSL using this extension?

I used this extension on one of my previous projects, and ssl connection works fine so far with these configs:

            $this->SMTPDebug = false;
            $this->Mailer='smtp';
            $this->SMTPAuth=true;
            $this->SMTPSecure='ssl';
            $this->Host="smtp.gmail.com";
            $this->Port=465;


            $this->CharSet = 'utf-8';
            $this->ContentType = 'text/html';
            $this->WordWrap = 70;
            $this->FromName=Yii::app()->name;
            $this->setFrom=Yii::app()->params->siteEmail;
             $this->Username =  // SMTP username
            $this->Password = // SMTP password

1

#29 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 513
  • Joined: 08-August 09

Posted 15 June 2012 - 09:22 PM

View Postpsolovyov, on 15 June 2012 - 06:14 PM, said:

PS: one more question, is there a way of connecting with SSL using this extension?

I used this extension on one of my previous projects, and ssl connection works fine so far with these configs:

            $this->SMTPDebug = false;
            $this->Mailer='smtp';
            $this->SMTPAuth=true;
            $this->SMTPSecure='ssl';
            $this->Host="smtp.gmail.com";
            $this->Port=465;


            $this->CharSet = 'utf-8';
            $this->ContentType = 'text/html';
            $this->WordWrap = 70;
            $this->FromName=Yii::app()->name;
            $this->setFrom=Yii::app()->params->siteEmail;
             $this->Username =  // SMTP username
            $this->Password = // SMTP password

0

#30 User is offline   psolovyov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 22-March 12

Posted 21 June 2012 - 01:45 PM

View Postyugene, on 15 June 2012 - 09:22 PM, said:

I used this extension on one of my previous projects, and ssl connection works fine so far with these configs:

            $this->SMTPDebug = false;
            $this->Mailer='smtp';
            $this->SMTPAuth=true;
            $this->SMTPSecure='ssl';
            $this->Host="smtp.gmail.com";
            $this->Port=465;


            $this->CharSet = 'utf-8';
            $this->ContentType = 'text/html';
            $this->WordWrap = 70;
            $this->FromName=Yii::app()->name;
            $this->setFrom=Yii::app()->params->siteEmail;
             $this->Username =  // SMTP username
            $this->Password = // SMTP password



i tried this but I get

SMTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host.
Transaction Failed! 



My settings:


Yii::app()->mailer->SMTPDebug = true;
Yii::app()->mailer->Mailer='smtp';
Yii::app()->mailer->SMTPAuth=true;
Yii::app()->mailer->SMTPSecure='ssl';
Yii::app()->mailer->Host="smtp.gmail.com";
Yii::app()->mailer->Port=465;


Yii::app()->mailer->From = 'info@*******.com';
Yii::app()->mailer->FromName = '****';
Yii::app()->mailer->setFrom('info@****.com');
Yii::app()->mailer->AddReplyTo('info@****.com');*/
Yii::app()->mailer->AddAddress($client_email->email); 

Yii::app()->mailer->ContentType = "text/html";
Yii::app()->mailer->CharSet = 'UTF-8';

Yii::app()->mailer->Subject = '****';
Yii::app()->mailer->Body = $message;  

Yii::app()->mailer->Username = "****@gmail.com";
Yii::app()->mailer->Password = "****";

if(!Yii::app()->mailer->Send())
{
	$this->actionBad();
	throw new CHttpException(500, 'Something went horribly wrong');
}
else
{
	$this->actionOk();					
}




EDIT: DUH!!! Talked to guys in chat and figured out that I need to use SMTPS instead of SMTP. WOrks perfectly now.

Thanks!!!
0

#31 User is offline   Ben Mazzarol 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 24-September 12

Posted 08 November 2012 - 03:06 AM

Hi Guys,

Apologies in advance if someone has already raised this, but there is a small logic error in the phpmailer class on line 1236 in the addAttachments function.

The last element of the array is set to 0, this is the unique id for the attachment, therefore it will stop any subsequent attachments from being added by the AttachAll function.

      $this->attachment[] = array(
        0 => $path,
        1 => $filename,
        2 => $name,
        3 => $encoding,
        4 => $type,
        5 => false,  // isStringAttachment
        6 => 'attachment',
        7 => 0, // <= THIS LINE HERE
      );


If you change it to increment you can send more than 1 attachment per email.

      $this->attachment[] = array(
        0 => $path,
        1 => $filename,
        2 => $name,
        3 => $encoding,
        4 => $type,
        5 => false,  // isStringAttachment
        6 => 'attachment',
        7 => count($this->attachment),
      );


The error is present in the current version of the mailer extension.

Cheers
Ben
0

#32 User is offline   MaziTizeh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 61
  • Joined: 12-June 12
  • Location:U.A.E

Posted 19 May 2013 - 09:48 AM

I tried to include the layout in my mailing function but unable to do.Here I am getting the mail with out layout.

this is my code...

in config main file
'mailer' => array(
                'class' => 'application.extensions.mailer.EMailer',
                'pathViews' => 'application.views.email',
                'pathLayouts' => 'application.views.email.layouts'
 ),


in my controller i using this code for sending the mail..

// Reading the content of mail from view..
$html = $this->renderPartial('//email/email',array(),true);
             Yii::app()->mailer->Body = $html;
            Yii::app()->mailer->Send();

0

#33 User is offline   @lex p&ian 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 16-December 11
  • Location:India

Posted 31 May 2013 - 05:45 AM

AddAttachment function is sending one attachment only, though we add multiple attachments
Actual code is

public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    try {
      if ( !@is_file($path) ) {
        throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
      }
      $filename = basename($path);
      if ( $name == '' ) {
        $name = $filename;
      }

      $this->attachment[] = array(
        0 => $path,
        1 => $filename,
        2 => $name,
        3 => $encoding,
        4 => $type,
        5 => false,  // isStringAttachment
        6 => 'attachment',
        7 => 0
      );

not working as it always sets 0 to 7th index of property 'attachment'

It worked if i set to rand()
public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    try {
      if ( !@is_file($path) ) {
        throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
      }
      $filename = basename($path);
      if ( $name == '' ) {
        $name = $filename;
      }

      $this->attachment[] = array(
        0 => $path,
        1 => $filename,
        2 => $name,
        3 => $encoding,
        4 => $type,
        5 => false,  // isStringAttachment
        6 => 'attachment',
        7 => rand()
      );

0

#34 User is offline   @lex p&ian 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 16-December 11
  • Location:India

Posted 31 May 2013 - 07:45 AM

I didn't listen Ben Mazzarol' comment.

If anyone wants to send more than one attachment go with his coding which is better than mine.
count($this->attachment)

0

#35 User is offline   brad.lyons 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 19-August 13

Posted 20 August 2013 - 11:03 PM

I am getting the error "Could not instantiate mail function". Does anyone know what might cause this or how to fix it?
0

#36 User is offline   balajivendan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 21-September 13

Posted 21 September 2013 - 02:02 AM

i am using yii codes in godaddy site,i want send email through smtp server in our site but could not connect google smtp server please help me.

my codes

'components'=>array(
'mailer' => array(
'class' => 'application.extensions.mailer.EMailer',
'pathViews' => 'application.views.email',
'pathLayouts' => 'application.views.email.layouts'
),)



public function actionmailsend() {
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->IsSMTP();
$mailer->IsHTML(true);
// $mailer->SMTPDebug = 2;
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "ssl";
$mailer->Host = "smtp.gmail.com";
//$mailer->Host = 'ssl://smtp.gmail.com:465';
$mailer->Port = 465;
$mailer->Username = "xxxx@gmail.com";
$mailer->Password = "xxxx";
$mailer->From = "from@gmail.com";
$mailer->FromName = "Test";
$mailer->AddAddress("example@gmail.com");
$mailer->Subject = "Someone sent you an email.";
$mailer->Body = "Hi, This is just a test email using PHP Mailer and Yii Framework.";

$mailer->Send();

}



my error is :could not connect smtp server
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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