Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Zend Mail smtp transport

Avatar of souvik2008
souvik2008Flag for India asked on
PHPEmail ServersEmail Protocols
3 Comments1 Solution2314 ViewsLast Modified:
Hello Experts,

I am struck in a position that I really need your help to move forward. I have a program whihc sends weekly newsletter via Zend mal smpt transport to about 2000 coustomers. At first in one hosting server it was working fine. But when I migrate it to a diifferent web server and configured the email accounts there. It stopped working . I get an error here with

Could not open socket .

My code which sends the mail is as follows. the same code worked before.
protected function sendNewsletter($from, $subject, $body) {
		$config = array('auth' => 'login',
                'username' => 'contact@piano-sheets.net',
                'password' => 'pass',
				'port' => 25);
				
		$transport = new Zend_Mail_Transport_Smtp('mail.piano-sheets.net', $config);
        $mail = new Zend_Mail();
        //$mail->addTo($from, $from);
        $mail->setFrom($from, 'Piano-Sheets');		
        $mail->setSubject($subject);
        $mail->setBodyHtml($body);
        
        $model = $this->_getMailingListModel();
        $mails = $model->findAll();
        if($mails == null)
            return;
        
        $counter = 0;
        $sent = 0;
        //echo $body;
		
        foreach($mails as $mailAdress) {
			if ($this->check_email_address($mailAdress['mailing_mail'])) {
				//print $email . ' is a valid email address.';
			} else {
				//print $mailAdress . ' is not a valid email address.';
				continue;
				
			}
			$mail->addBcc($mailAdress['mailing_mail']);			
            $counter++;
            $sent++;
			
            if($sent == count($mails)) {
            	$mail->addBcc('to.souvik@live.com');
            	//$mail->addBcc('dkartash@gmail.com');
            }
            	
            if($counter == 100 || $sent == count($mails)) {
                try {
                    $mail->send($transport);
					//$mail->send();
					
                } catch (Zend_Mail_Transport_Exception $e) {
                    //print $e;
					die("hello");
                    exit;
                    // Do something here, mail failed to send
                }
                //$mail->send($transport);
				//$mail->send();
                //echo $mail->getRecipients();
                $mail->clearRecipients();
                $counter = 0;
            }            
        }        
		$this->_helper->layout->disableLayout();		
		$this->_helper->viewRenderer->setNoRender();		        
		$this->_response->appendBody(Zend_Json::encode("SUCCESS: Sending mail finished. Newsletter sent on " . count($mails) . " mails! "));		
    }
ASKER CERTIFIED SOLUTION
Avatar of jar3817
jar3817

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers