ZF2 Zend\Mail usage with gmail

Example usage of Zend Mail in ZF2 for sending e-mail by gmail.


<?php
require_once './Zend/Loader/StandardAutoloader.php';

$loader = new Zend\Loader\StandardAutoloader( array( 'autoregister_zf' => true));
$loader->register( );

use Zend\Mail;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;

$options = new SmtpOptions( array(
"name" => "gmail",
"host" => "smtp.gmail.com",
"port" => 587,
"connection_class" => "plain",
"connection_config" => array( "username" => "mail1@gmail.com",
"password" => "oleaodeSodor","ssl" => "tls" )
) );

$mail = new Mail\Message();
$mail->setBody('Hello there!');
$mail->setFrom('mail1@gmail.com', 'Pat');
$mail->addTo('mail2@gmail.com', 'Andre');
$mail->addCC( 'ao@gmail.com' );

$mail->setSubject('Hello today ' . date( "d-m-Y" ));

$transport = new SmtpTransport();
$transport->setOptions( $options );
$transport->send($mail);

Anúncios

Zend Framework Zend Db Profiler

Analyzing database SQL query’s within Zend Framework Front Controllers isn’t difficult here’s an example:

$bootstrap = $this->getFrontController()->getParam(“bootstrap”);

if ($bootstrap->hasPluginResource(“db”)) {
      $dbResource = $bootstrap->getPluginResource(“db”);
      $db = $dbResource->getDbAdapter();

$profiler = $db->getProfiler();
$profiler->setEnabled(true);

}
            foreach ($devs->getDevices($cliente->idcliente) as $equip) {

                $equip->findDependentRowset(“DM_Model_Services”, “equipment”);
    $query = $profiler->getLastQueryProfile();

    echo $query->getQuery();      

          }

My database config in application.ini:

resources.db.adapter         = pdo_mysql
resources.db.params.host     = 127.0.0.1
resources.db.params.username = user
resources.db.params.password = pass
resources.db.params.dbname   = sal_db

This will give an output like:

SELECT `service`.* FROM `service` WHERE (`idequipment` = 70)