mbi
(mbi)
June 9, 2009, 11:51pm
21
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){}
MetaYii
(Metayii Framework)
June 10, 2009, 1:13am
22
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.
mbi
(mbi)
June 10, 2009, 10:11am
23
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
sn0rcha
(Ben)
March 5, 2010, 8:17am
24
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
lruiz
(Oracleruiz)
June 11, 2010, 5:06pm
25
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?
aqge
(Programmer Riau)
November 11, 2010, 6:34am
26
'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?
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.
yugenekr
(Yugenekr)
June 16, 2012, 2:20am
28
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
yugenekr
(Yugenekr)
June 16, 2012, 2:22am
29
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 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!!!
bmazzarol
(Bmazzarol)
November 8, 2012, 8:06am
31
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
m7dmh
(M7d Mh)
May 19, 2013, 2:48pm
32
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();
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()
);
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)
brad.lyons
(Brad Lyons)
August 21, 2013, 4:03am
35
I am getting the error "Could not instantiate mail function". Does anyone know what might cause this or how to fix it?
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