Help: send mail using Zend Framework

Started on the old forum in February 2011 · view the original in the archive · old links redirect here

2 replies · 1,569 views · started 15 years ago · 1 min read

2 participants
Mysterio Lead · 630 posts #1

Hello guys,

I am having strange problem trying to send e-mail using Zend Framework. I am using same code as suggested by Zend experts, but still not working. Someone who works with Zend may faced the same problem, or may just know what the problem is. Most of the times, that code is being skipped as it was some commented lines: nothing happens. May just be the host wrong? Because some times I just get this message: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'Connection refused' in /data/value/www/development/test/library/Zend/Mail/Protocol/Abstract.php

require_once 'Zend/Mail/Transport/Smtp.php';
$host='localhost';
$tr = new Zend_Mail_Transport_Smtp($host);
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
				
$body='Test mail only!';				
$mail->setFrom('mailserver@dev.al');
$mail->addTo('emailserverfeedback@dev.al');
$mail->setSubject('Test Subject');
$mail->setBodyHtml($body);
$mail->send();

Thanks to everyone!

mysterio.al - programming is a functional art

wap2k Developer · 168 posts #2

I have never used the Zend Framework but i took a look at the Zendmail API reference. mail.php sourecode and came up with this.

<?php
   require_once 'Zend/Mail/Transport/Smtp.php';

  // Default is 127.0.0.1 (localhost) change this to your smtp server address  
  $hostname = null;  

  // SMTP Authentication Information Comment out if not needed.
  $ConfigParam = array('auth' => 'login', 'username' => 'SMTPUsername', 'password' => 'SMTPPassword');
  
  // New instance of Zend_Mail_Transport_Smtp
  
  $tsInstance = new Zend_Mail_Transport_Smtp($hostname,  $ConfigParam);
  
  // We want to use this Transport used by send()
  Zend_Mail::setDefaultTransport($tsInstance);
  
  // Zend Mail Instance
  
  $emailMsg = new Zend_Mail();
  $body = 'Test mail only!';
  
  // Defaults to iso-8859-1
  $charset = getCharset();
  
  // Defaults to Zend_Mime::ENCODING_QUOTEDPRINTABLE;
  $encoding = getEncodingOfHeaders();
  
// You can add multiple emails here
  $emailMsg->addTo('emailserverfeedback@dev.al');

// Body of Email
  $emailMsg->setBodyHtml($body, $charset, $encoding);
  
  try {
      // Prepare the message we want to send. 
      if ($emailMsg->getFrom() == null)
          $emailMsg->setFrom('mailserver@dev.al');
      if ($emailMsg->getSubject() == null)
          $emailMsg->setSubject('Test Subject');
      // $emailMsg->send($tsInstance);
      $emailMsg->send();
  }
  catch (Zend_Mail_Exception $MailException) {
      // holy Crap batman. We have a error.
      echo $MailException->getMessage();
  }
?>

I think you may have an incorrect mail server address; SMTP authentication is needed or Mail server is rejecting you.

The above is mostly original code not a copy and paste so there may be syntax errors. Please Check 🙂

Mysterio Lead · 630 posts #3

Thank you! Probably the SMTP cannot be "localhost". I will change it later and inform for the news.

mysterio.al - programming is a functional art

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close