Programmer's Reference Guide

Introduction

Sending via SMTP

To send mail via SMTP, Zend_Mail_Transport_Smtp needs to be created and registered with Zend_Mail before the send() method is called. For all remaining Zend_Mail::send() calls in the current script, the SMTP transport will then be used:

Example #1 Sending E-Mail via SMTP

  1. $tr = new Zend_Mail_Transport_Smtp('mail.example.com');
  2. Zend_Mail::setDefaultTransport($tr);

The setDefaultTransport() method and the constructor of Zend_Mail_Transport_Smtp are not expensive. These two lines can be processed at script setup time (e.g., config.inc or similar) to configure the behavior of the Zend_Mail class for the rest of the script. This keeps configuration information out of the application logic - whether mail is sent via SMTP or » mail(), what mail server is used, etc.


Introduction

Comments

$tr = new Zend_Mail_Transport_Smtp('out.telenet.be');
$mail->setFrom('a@gmail.com', 'Server');
$mail->addTo($to, 'a@gmail.com');
$mail->setSubject($subject);
$mail->send();
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setBodyText($body);
public function send()
{
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'username@gmail.com', 'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

$mail = new Zend_Mail();
if (strtolower($this->getType()) == 'html')
$mail->setBodyHtml($this->getBody());
}
else {
$mail->setBodyText($this->getBody());
}

$mail
->setFrom($this->getFromEmail(), $this->getFromName())
->addTo($this->getToEmail(), $this->getToName())
->setSubject($this->getSubject());

$mail->send($transport);

return $this;
}
test
thanks this is really helpful
I am a new learner of ZendFramework,and I have less knowledge about php. Now I want to write a program for sending mail, I don't how to start. asking for help.

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual