Help: send mail using Zend Framework

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help: send mail using Zend Framework

    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

    PHP Code:
    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

    #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 Code:
    <?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
    Last edited by wap2k; 10.02.11, 19:14.

    Comment


      #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

      Comment

      Working...
      X