Jump to content

Recommended Posts

Can anybody help me with mail?

This is the code:

<?php
if ($_REQUEST['email'] != null){
$email = "jbalout@gmail.com";
$subject = "New Password";
$dbhost = "127.0.0.1";
$dbname = "nova";
$dbuser = "root";
$dbpass = "blabla";
  mysql_connect($dbhost, $dbuser, $dbpass) or error("Could not connect: " . mysql_error());
mysql_select_db($dbname) or error(mysql_error());
$marriedto2 = mysql_query(sprintf("SELECT * FROM users WHERE username = '" . $_REQUEST['name'] . "'"));
                                $arrInfo   = mysql_fetch_assoc($marriedto2);
                                $to    = $arrInfo['email'];
		if ($to == $sender)
  {
  $password = md5("blabla");
mysql_query("UPDATE users SET password = '" . $password . "' WHERE username = '" . $_REQUEST['name'] . "'");                
  $message = " It seems you have forgoten your password, here's a new one, login to the manager and change it to a new one (make sure you remember it), by using this password: <br> bla bla";
  $username = $_REQUEST['name'] ;
  if (mail($to, $subject, $message, "From:" . $email)){
echo 'Your new password has been sent to your mail.';
}
else if (!mail($to, $subject, $message, "From:" . $email)){
echo'Please try again...';
  }
  }
  }
else
//if "email" is not filled out, display the form
  {
  ?>
  <form action="
  <?php
echo $_SERVER['PHP_SELF'];
?>" method="post">         
<table border="0">
<tr><td>Email:</td><td>
<input type="text" name="email" placeholder="Email that you registered with..." maxlength="50">
</td></tr>
<tr><td>Name:</td><td>
<input type="text" name="name" placeholder="Username..." maxlength="10">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" 
value="Submit" style="height: 25px; width: 100px"></th></tr></table>
</form>
  <p> Make sure that you know it will take about 5 minutes for you to receive the mail, it will also appear in your junk.</p>
<?php
} 
?>

Can anybody help? The form shows but when I click submit, it shows me a blank page.Help?

Link to comment
https://forums.phpfreaks.com/topic/281293-mail-help/
Share on other sites

If you're running into a blank page and you have no clue what is wrong, you should consider turning on PHP error reporting.

 

To display all PHP error messages you could include this line of code on the top of the file:

// Report all PHP errors
error_reporting(-1);

Add: If somehow your display_errors directive in php.ini is set to "Off", try next

ini_set('display_errors',1); 
error_reporting(E_ALL);
Link to comment
https://forums.phpfreaks.com/topic/281293-mail-help/#findComment-1445620
Share on other sites

Hi, i don't know what exactly is the problem as its too vague and lacking alot of detail however i will point out some things you can do to make your code more manageable and safe

 

1. put your DB connection code in a separate file and require it at the top of all php file that need it.

2. always use a form of escaping the DB input as taking the values from user input and putting them straight into the DB is very dangerous

3. its bad practise to use PHP_SELF to reload the page with a form on it, create the form on a seperate page and use the filename of the complete script in the action part so the page with the form and values goes straight to that file.

4. remember that using $_REQUEST[''] variable will search $_GET[''] $_POST[''] $_COOKIE[''] so make sure you dont have a $_POST['user'] and a $_GET['user'] with different values.

 

Hope this helps :)

Link to comment
https://forums.phpfreaks.com/topic/281293-mail-help/#findComment-1445695
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.