0

<?php

require_once 'lib/swift_required.php';

$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$headers = "From: Sebastian@Thorn.se" . "\r\n";

$conn = new mysqli('localhost', 'root', 'rushndie', 'bookmarks');
$username = $_POST['username']
$result2 = $conn->query("select * from user
where username='".$username."'
and passwd = sha1('".$password."')");

$row = $result->fetch_object();

$email = $row->email;
$message = Swift_Message::newInstance()
->setFrom(array('sebastian@thorn.se' => 'SEBASTIAN JOHANSSON THORN'))
->setSubject('Password')
->setTo(array('$email'))
->setBody('"Ditt lösenord är: ".$password."\r\n"
."Tips: Ändra ditt lösenord när du loggat in.\r\n";');
$result = $mailer->send($message);

print_r($result);

?>

Where have I done this wrong?

I want to collect the password from the database
and then send it to the user.

3
Contributors
4
Replies
15
Views
4 Years
Discussion Span
Last Post by IIM
0

forgot_passw2.php

    <form class="cygnaform" action="forgot_passwd.php" method="post">
        <table width="188" cellpadding="2" cellspacing="0">
          <tr>
            <td><h4><br>
              Återställ lösenord</h4>
              <span class="text1">Skriv ditt användarnamn:</span><br><input class="cygnaTextbox textarea" type="text" name="username" size="16" maxlength="16"/><br><br>      <input type="submit" value="Skicka nytt!"/>  </td></tr>
        </table></form>

forgot_passw.php

    <?php

    require_once 'lib/swift_required.php';

    $transport = Swift_MailTransport::newInstance();
    $mailer = Swift_Mailer::newInstance($transport);
    $headers = "From: Sebastian@Thorn.se" . "\r\n";

    $conn = new mysqli('localhost', 'root', 'password', 'bookmarks');
    $username = $_POST['username']
    $result2 = $conn->query("select * from user
    where username='".$username."'
    and passwd = sha1('".$password."')");

    $row = $result->fetch_object();

    $email = $row->email;
    $message = Swift_Message::newInstance()
    ->setFrom(array('sebastian@thorn.se' => 'SEBASTIAN JOHANSSON THORN'))
    ->setSubject('Password')
    ->setTo(array('$email'))
    ->setBody('"Ditt lösenord är: ".$password."\r\n"
    ."Tips: Ändra ditt lösenord när du loggat in.\r\n";');
    $result = $mailer->send($message);

    print_r($result);

    ?>

Edited by Vingklippt

0

Line 11 => $result2, but you then use $result in line 15 & 24
Line 13 => You check where against both username and passwd, but you only get POST data for username.

Other than that i have not used "Swift_Mailer" before, so maybe someone can shed some light, or have you reviewed the HOWTO where the class was downloaded from?

0
  $result2 = $conn->query("select * from user
     where username='".$username."'
     and passwd = sha1('".$password."')");//forgot password doesn't contain password

Firstly person has forgot his password,how will he enter password.

It must be

$result2 = $conn->query("select * from user
    where username='".$username."'");

Secondly,
$password is undefined.
after line 17 add this line,

$password=$row->passwd;//assuming passwd is field containing password.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.