Richard Parnaby-King

Web Developer – PHP, Zend Framework and Actionscript 3

Posted on | | 1 Comment

It may be that your server does not allow you to send emails, for example a shared server or localhost that you cannot configure.

In either case, if you are using the Zend Framework’s Zend_Mail component, you can have your application send the emails through GMail.

Configuration

In your application.ini file, add the following:

;email
email.server = smtp.gmail.com
email.username = username
email.password = password
email.ssl = ssl
email.port = 465

Obviously substituting ‘username’ and ‘password’ for your username and password.

In your bootstrap file, add the following _init function.

<?php
  /**
   * If running on development server (localhost), set up email to use STMP protocol set up in application.ini file.
   */
  protected function _initMailsetup()
  {
    $aConfig = $this->getOptions();
    $this->_aMailConfig = array(
	  'auth' => 'login',
	  'username' => $aConfig['email']['username'],
	  'password' => $aConfig['email']['password'],
	  'ssl' => $aConfig['email']['ssl'],
	  'port' => $aConfig['email']['port']);
    $this->_strSmtp = $aConfig['email']['server'];
    Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp($this->_strSmtp, $this->_aMailConfig));
  }

You do not need to call this function, your Zend Framework application will call every _init* function in your bootstrap file.

Every email that is sent using the Zend_Mail component will now go through your gmail account. Happy Zending =)

Posted By:

Comments

  • ABOUT

    Having five years of programming experience in PHP, Zend Framework and ActionScript3, I have a very strong working knowledge of object orientated programming.

    I am a PC Gamer! Playing FPS, RTS, RPG and the occasional MMO since 1996 I have a huge number of a variety of fast-paced games.

  • Recent Posts

  • Categories

  • RSS SUBSCRIBE TO OUR FEED

  •