0

I'm trying to send out a mail using Swiftmailer. I have the following code in which I send out a mail:

if(isset($_POST['submit'])) {

        $token = substr(sha1(mt_rand()),0,22);

        $resetAccount = "UPDATE members 
                          SET token='".$token."', 
                              token_expire='".date("Y-m-d H:i:s", strtotime('+1 hours'))."'
                          WHERE username='".$_POST['username']."'
                            AND email='".$_POST['email']."'";

        $exec = $db->query($resetAccount);

        if($exec->rowCount()) {
            $transport = Swift_MailTransport::newInstance();

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

            $recoverylink = "<a href='http://www.".$_SERVER['SERVER_NAME']."/admin/recover.php?token=".$token."'>wachtwoordherstel voor ".$_POST['username']."</a>";

            $mailbody = 'Beste '.$_POST['username'].',<br><br>U heef een token voor wachtwoordherstel aangevraagd. Het komend uur kunt u uw wachtwoord veranderen via deze link: '.$recoverylink;


            $message = Swift_Message::newInstance()
              ->setSubject("Wachtwoordherstel voor ".$_POST['username'])
              ->setFrom(array('cms@'.$_SERVER['SERVER_NAME'] => "Q Sites CMS"))
              ->setTo(array($_POST['email'] => $_POST['username']))
              ->setBody($mailbody, 'text/html')
            ;


            $result = $mailer->send($message);

            echo "<div class='alert'>Een e-mail met instructies is verzonden naar ".$_POST['email'].".</div>";
        }
        else {                  
            echo "<div class='alert'>Uw account is niet gevonden.</div>";
        }

    }

The code get's past the if($exec->rowCount()) { and thus echoes echo "<div class='alert'>Een e-mail met instructies is verzonden naar ".$_POST['email'].".</div>"; but the mail isn't sent. What am I doing wrong?

The form from which input is used:

<form id="login-form" method="post" class="form">
    <input type="text" name="username" placeholder="Gebruikersnaam" required >
    <input type="email" name="email" placeholder="E-mail" class="email" required >
    <input type="submit" name="submit" value="Herstel">
</form>
  • Did you dump `$result` to see what's in there? Did you check your mailserver logs? Did you check your spam folder? – Maerlyn Oct 02 '14 at 12:33
  • Thanks for the suggestions. I did check my spamfolder, I did dump $result, nothing strange there. I don't have access to my mailserver logs. –  Oct 02 '14 at 12:40

0 Answers0