电子邮件不发送,PHP和SwiftMailer

时间:2014-02-17 19:34:38

标签: php smtp swiftmailer silex mandrill

我有我的代码

<?php


namespace Spika\Controller;

use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\ParameterBag;

class SendPasswordController extends SpikaBaseController
{
public function connect(Application $app)
{
    $controllers = $app['controllers_factory'];
    $self = $this;

    // check unique controller
    $controllers->get('/resetPassword', function (Request $request) use ($app,$self) {

        $email = $request->get('email');

        $user = $app['spikadb']->findUserByEmail($email);

        if (isset($user['_id'])) {

            $user = $app['spikadb']->findUserById($user['_id'],false);

            $resetCode = $app['spikadb']->addPassworResetRequest($user['_id']);

            $resetPasswordUrl = ROOT_URL . "/page/resetPassword/" . $resetCode;

            $body = "Please reset password here {$resetPasswordUrl}";

            try{

                if(SEND_EMAIL_METHOD == EMAIL_METHOD_LOCALSMTP){

                    $message = \Swift_Message::newInstance()
                        ->setSubject("Spika Reset Password")
                        ->setFrom(AdministratorEmail)
                        ->setTo($user['email'])
                        ->setBody($body);

                    $mailer = \Swift_Mailer::newInstance();

                    $mailer->send($message);

                }

                if(SEND_EMAIL_METHOD == EMAIL_METHOD_GMAIL){

                    $transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587)
                        ->setUsername('me@me.com')
                        ->setPassword('89f7g8dfg8d7fg0');

                    $message = \Swift_Message::newInstance()
                        ->setSubject("Spika Reset Password")
                        ->setFrom(AdministratorEmail)
                        ->setTo($user['email'])
                        ->setBody($body);

                    $mailer = \Swift_Mailer::newInstance($transport);

                    $mailer->send($message);

                }


            } catch(\Exception $e){

            }

            return 'OK';

        }else{

            return $self->returnErrorResponse("invalid email");

        }

        return 'OK';

    });

    return $controllers;
}

}

?>

我正在使用Mandrill和SwiftMailer。邮件没有发送。我正在使用this代码。看起来那里有一种叫做Silex的东西。看起来脚本没有发送它们,因为它们没有出现在Mandrill上。任何帮助,将不胜感激。

0 个答案:

没有答案