• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

GhazaliTajuddin.com

Another Kuantan Blogger

  • Home
  • Blog
    • Kuantan
    • Foods
    • Technology
    • Health
  • Stock Photography
    • Senarai Microstock Agency
    • Membuka akaun contributor Shutterstock.com
    • Tips untuk 10 keping gambar pertama Shutterstock.com
    • Mengapa Shutterstock.com reject gambar / submission
    • Model Release
    • Bagaimana withdraw earning daripada Fotolia
    • Bagaimana untuk mengisi keyword kepada imej dengan menggunakan Adobe Photoshop
You are here: Home / General / Yii Example How To Install Mail Extension (Swiftmailer Wrapper)

Yii Example How To Install Mail Extension (Swiftmailer Wrapper)

April 19, 2012 by ghazalitajuddin 4 Comments

Yii Framework
Yii Framework
  • Download this mail extension here  http://www.yiiframework.com/extension/mail.
  • Extract the files.
  • Move the vendors folder to protected/components/vendors/
  • Move YiiMail.php and YiiMailMessage.php to protected/components/
  • Add on protected/config/main.php

[php]

‘components’=>array(

…
‘mail’ => array(
‘class’ => ‘YiiMail’,
‘transportType’ => ‘php’,
‘transportType’ => ‘smtp’,
‘transportOptions’=>array(
‘host’=>’ghazalitajuddin.com’,
//’encryption’=>’tls’,
‘username’=>’***@ghazalitajuddin.com’,
‘password’=>’******’,
‘port’=>25,
),
‘logging’ => true,
‘dryRun’ => false
),

…

),

[/php]

  • Configure in controller

[php]</pre>
$message = new YiiMailMessage;
$message->setBody($model->message);
$message->subject = $model->subject;
$message->addTo($model->to);
$message->from = Yii::app()->params[‘adminEmail’];
Yii::app()->mail->send($message);
<pre>[/php]

  • Create our model

[php]
class EmailForm extends CFormModel
{
public $email;
public $to;
public $subject;
public $message;
public $from;

/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array(’email, to, subject, message’, ‘required’),
// email has to be a valid email address
array(’email’, ’email’),
// verifyCode needs to be entered correctly
//array(‘verifyCode’, ‘captcha’, ‘allowEmpty’=>!CCaptcha::checkRequirements()),
);
}

/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
‘verifyCode’=>’Verification Code’,
);
}
}
[/php]

  • Finally create our view

[php]
<?php
$this->pageTitle=Yii::app()->name . ‘ – Email Others’;
$this->breadcrumbs=array(
‘Email’,
);
?>

<h1>Email others</h1>

<?php if(Yii::app()->user->hasFlash(’email’)): ?>

<div class="flash-success">
<?php echo Yii::app()->user->getFlash(’email’); ?>
</div>

<?php else: ?>

<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(
‘id’=>’email-form’,
‘enableClientValidation’=>true,
‘clientOptions’=>array(
‘validateOnSubmit’=>true,
),
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,’email’); ?>
<?php echo $form->textField($model,’email’); ?>
<?php echo $form->error($model,’email’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’to’); ?>
<?php echo $form->textField($model,’to’); ?>
<?php echo $form->error($model,’to’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’subject’); ?>
<?php echo $form->textField($model,’subject’,array(‘size’=>60,’maxlength’=>128)); ?>
<?php echo $form->error($model,’subject’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’message’); ?>
<?php echo $form->textArea($model,’message’,array(‘rows’=>6, ‘cols’=>50)); ?>
<?php echo $form->error($model,’message’); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,’from’); ?>
<?php echo $form->textArea($model,’from’); ?>
<?php echo $form->error($model,’from’); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton(‘Submit’); ?>
</div>

<?php $this->endWidget(); ?>

</div><!– form –>

<?php endif; ?>
[/php]

Filed Under: General, Technology Tagged With: Component, Controller, Extension, Framework, Kuantan, kuantan programmer, kuantan web developer, kuantan webmaster, Mail, Malaysian Yii, model, MVC, OOP, PHP, programmer, sendmail, SwiftMailer, View, Widget, wordpress, yii, Yii Framework

Reader Interactions

Comments

  1. varun says

    August 31, 2012 at 6:13 am

    i need to know whats the name of the model and the view file we create and how are they called and connected …
    can i create different templates for eg different forms and put conditions eg ..
    if send to client company send _form1
    other wise send _form 2??
    i am new to yii .. please help me implement the above .. thanks

    Reply
  2. M.Pathma says

    October 29, 2012 at 9:30 am

    Hi, Ghazali Tajuddin,
    Nice work on the YiiMail. Thanks for sharing.
    My name is M.Pathma from Promosys Technology, We are looking for PHP Developer using YII Framework under WAMP or XAMPP platform. Basically we are developing WebApps for Monitoring Solution, Promosys is dedicated for Monitoring Solution development. check our more about us at http://www.mypromosys.com

    If you have any friends in Klang area looking for job under PHP + WAMP (or XAMPP) please share my contact information with them. they can contact me at mpathma@gmail.com or call in at 03-33231001

    M.Pathma

    Reply
  3. Kaungkhant Mintun says

    January 19, 2015 at 5:41 pm

    I am new in Yii.Can I get this source codes,plz sir? :3

    Reply
    • Ahmad Ghazali Ahmad Tajuddin says

      January 14, 2016 at 3:18 pm

      Yes. Tq.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

“Solat. Sabar. Syukur. Senyum. Sedekah.”

For Collaboration, Events & Review, kindly contact me at +6016[-]9212092 or click Whatsapp button on this page.

Sponsor

Recent Posts

BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.

User Roles And Permissions Without Package Laravel 10

Laravel Many To Many Relationship

Makan malam bersama keluarga di Awangan Palace

Sarapan pagi di Warung Gulai Kawah

Recent Comments

  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Personal Tips Berhenti Merokok
  • helmi on Personal Tips Berhenti Merokok
  • ghazalitajuddin on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • ghazalitajuddin on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!
  • Mal on Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.
  • Firdaus on Air tangki radiator Proton Exora cepat kering? Cuba tukar penutup radiator!

My Link

  • Takaful Insurance Web

JJCM

Sarapan pagi di Warung Gulai Kawah

Kuih Akok Kedut Kelantan

Nasi Lemak Kukus Restoran Zaman. Otai masih berbisa.

Coke Coffee Caramel ~ Not recommended!

Popia basah terbaik di Kuantan?

Tags

bebas rokok berhenti merokok breakfast Controller Framework Gezzeg Photography & Design health jalan-jalan cari makan jalan-jalan cari makan kuantan jjcm jjcm kuantan Jurufoto Kuantan Kuantan Kuantan Photographer kuantan programmer kuantan web developer kuantan webmaster laravel merokok merbahayakan kesihatan model MVC nikmat rokok OOP Pahang Pahangtourism pahang tourism Photo Manipulation PHP rajalanun retired smoking revisit pahang 2018 shutterstock stop smoking stop smoking tips stop smoking withdrawal symptom tips tips berhenti merokok View visit malaysia 2020 visit pahang visitpahang white wordpress yii Yii Framework

Recent Posts

  • BadMethodCallException Method Illuminate\Database\Eloquent\Collection::roles does not exist.
  • User Roles And Permissions Without Package Laravel 10
  • Laravel Many To Many Relationship
  • Makan malam bersama keluarga di Awangan Palace
  • Sarapan pagi di Warung Gulai Kawah

Copyright © 2025 — Ghazali Tajuddin • All rights reserved. •