如何知道邮件是否发送在zend 2中

时间:2016-05-11 09:32:48

标签: php zend-framework zend-framework2

我写了一封发送电子邮件的代码,成功发送后无法返回任何状态

$message = new \Zend\Mail\Message();
    $htmlPart = new MimePart($body);
    $htmlPart->type = "text/html";

    $textPart = new MimePart($body);
    $textPart->type = "text/plain";

    $body = new MimeMessage();
    $body->setParts(array($textPart, $htmlPart));

    $message->setBody( $body );
    $message->setFrom('it.test.com');
    $message->addTo( $this->to ); // $message->addTo($RequesterEmailAddr);
    $message->setSubject( $this->subject );
    $message->getHeaders()->get('content-type')->setType('multipart/alternative');
    $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();  
    $smtpOptions->setHost('smtp.test.com')
                ->setConnectionClass('login')
                ->setName('smtp.test.com')
                ->setConnectionConfig(array(
                    'username' => $this->Username_Email,
                    'password' => $this->Password_Email,
                    'ssl' => 'tls',
                    'port' => 25,
                ));
    $transport  = new \Zend\Mail\Transport\Smtp($smtpOptions);
    $MailStatus = $transport->send($message) ;

$MailStatus  

以上变量在成功发送电子邮件后不返回任何内容 Plase帮帮我

1 个答案:

答案 0 :(得分:0)

这是正常的,因为send方法不会返回任何内容 但你可以检查是否出现问题'Transport \ File和Transport \ Smtp在出现问题时抛出Exception \ RuntimeException。文件传输器执行此操作,例如,当它无法写入文件时。'