1

我使用 ZF2 的 Message 类来尝试发送电子邮件。但是,执行下面的代码后,页面尝试重定向,大约一分钟后给我一个“本地主机已超时”错误。有任何想法吗?

    $message = new Message();
    $message->addTo('ToEmail@gmail.com')
      ->addFrom('FromEmail@gmail.com')
      ->setSubject('Greetings and Salutations!')
      ->setBody("Sorry, I'm going to be late today!");

    // Setup SMTP transport using LOGIN authentication
    // Setup SMTP transport using PLAIN authentication over TLS
    $transport = new SmtpTransport();
    $options   = new SmtpOptions(array(
        'name'              => 'localhost',
        'host'              => 'localhost',
        'port'              => 8888, // Notice port change for TLS is 587
        'connection_class'  => 'plain',
        'connection_config' => array(
            'username' => 'FromEmail@gmail.com',
            'password' => 'FromPassword',
            'ssl'      => 'tls',
        ),
    ));
    $transport->setOptions($options);
    $transport->send($message);
4

1 回答 1

0

我可以使用 Zend Framework 2.0 发送电子邮件。请遵循以下代码集。

$options = new Mail\Transport\SmtpOptions(
                                    'smtp_options' => array(
            'name' => 'localhost',
            'host' => 'smtp.gmail.com',
            'port'=> 587,
            'connection_class' => 'login',
            'connection_config' => array(
                'username' => '<your gmail account username>@gmail.com',
                'password' => '<your gmail account password>',
                'ssl'      => 'tls'
            ),
        )
                            );


                            $content = 'Message to be sent in the email.(goes here)';  

                            // make a header as html  
                            $html = new MimePart($content);  
                            $html->type = "text/html";  
                            $body = new MimeMessage();  
                            $body->setParts(array($html)); 

                            // instance mail   
                            $mail = new Mail\Message();  
                            $mail->setBody($body); // will generate our code html from template.phtml  
                            $mail->setFrom('FromEmail@gmail.com');  
                            $mail->setTo('ToEmail@gmail.com');
                            $mail->setSubject('Subject for sending email.');

                            $transport = new Mail\Transport\Smtp($options);
                            $transport->send($mail);

如果您在 dineshs@mindfiresolutions.com 遇到任何问题,请告诉我

于 2013-12-04T10:17:11.650 回答