SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot clarnp49's Avatar
    Join Date
    Sep 2004
    Location
    Bowie MD
    Posts
    184
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Mail Sending Problem

    This is a serious problem for me. I am using some code from a script I found and like because it's complete but I am having one problem with it and it's easier to ask her because then I get an explanation of whats wrong.
    The problem is it won't send the email. It fails and throws the error message of failed to send.
    It used to work and now it does not, the Webhost says they did some upgrades to PHP Version 5 but I am using Version 4 with this script.

    Below is the code for the forgot password, the problem is because the password is MD5 I can't it again, and if I can't send an email then I won't know what the password is. I have resorted to posting the information on fail just so the password can be retrieved, but that's insecure.

    PHP Code:
    function Forgot_pwd_form(){
    global 
    $error_msg;

    echo 
    "<center><font class=\"title\">"._SEND_NEW_PASSWORD."</font>
    <form method='POST' action='users.php'>
    <table border='0' cellpadding='4'>
            <tr>
                    <td bgcolor='#E2E2E2'>"
    ._USERNAME." :</td>
                    <td bgcolor='#E2E2E2'><input type='text' name='username' size='11'></td>
            </tr>
            <tr>
                    <td bgcolor='#E2E2E2'>"
    ._EMAIL." :</td>
                    <td bgcolor='#E2E2E2'><input type='text' name='email' size='11'></td>
            </tr>
            <tr>
                    <td>&nbsp;</td>
                        <td>
                        <input type='hidden' name='maa' value='do_Forgot_pwd'>
                        <input type='submit' value='"
    ._SEND_PASSWORD."'></p>
                    </td>
            </tr>
    </table><center>
    $error_msg</center>
    </form>"
    ;
    }

    function 
    Forgot_pwd(){
             global 
    $user$prefix$db;

             
             
    Forgot_pwd_form();
             
    }

    function 
    do_Forgot_pwd(){
             global 
    $user$prefix$db$email$username$error_msg$site_name ,$site_email$site_url;

             
    $result $db->sql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND email='$email'");
             
    $check $db->sql_numrows($result);
             if(
    $check == 1){

             function 
    new_pwd() {
                      
    $chars "abchefghjkmnpqrstuvwxyz0123456789";
                      
    srand((double)microtime()*1000000);
                      
    $i 0;
                      while (
    $i <= 7) {
                                
    $num rand() % 33;
                                
    $tmp substr($chars$num1);
                                
    $pwd $pwd $tmp;
                                
    $i++;
                      }
                      return 
    $pwd;
             }
             
    $new_pwd new_pwd();
             
    $md5_password md5($new_pwd);
             
    $sql $db->sql_query("UPDATE ".$prefix."_users SET password='$md5_password' WHERE email='$email'");

             
    $eol ="\r\n";
             
             
    $subject ""._NEW_PASSWORD."";
             
    $message "$eol";
             
    $message .= ""._HELLO.$username$eol";
             
    $message .= $eol";
             
    $message .= ""._YOU_ARE_RECEIVING_EMAIL.$site_name$eol";
             
    $message .= "  $eol";
             
    $message .= ""._HERE_ISIT_BELOW.$eol";
             
    $message .= "--------------------------$eol";
             
    $message .= ""._USERNAME.": $username  $eol";
             
    $message .= ""._PASSWORD.": $new_pwd  $eol";
             
    $message .= "--------------------------  $eol";
             
    $message .= ""._YOU_MAY_LOGIN_BELOW."  $eol";
             
    $message .= "$site_url  $eol";
             
    $message .= "  $eol";
             
    $message .= ""._YOU_CAN_OFCOURSE_CHANGE_PWS.$eol";
             
    $message .= "  $eol";
             
    $message .= "-- $eol";
             
    $message .= "-"._THANKS."  $eol";
             
    $message .= "$site_name $eol";
             
    $message .= "   $eol";
             
    $message .= ""._THIS_EMAIL_AUTO_GENERATED.$eol";
             
    $message .= ""._DONT_RESPOND_WILL_IGNORED.$eol";


              
    #set email headers  to aviod spam filters
              
    $headers .= "From: ".$site_name."<".$site_email.">".$eol;
              
    $headers .= "Reply-To: ".$site_name."<".$site_email.">".$eol;
              
    $headers .= "Return-Path: ".$site_name."<".$site_email.">".$eol;
              
    $headers .= "Message-ID: <".time()."-".$site_email.">".$eol;
              
    $headers .= "X-Mailer: PHP v".phpversion().$eol;
              
    $headers .= 'MIME-Version: 1.0'.$eol.$eol;

             if(!
    mail($email,$subject,$message$headers)){
                 die (
    ""._EMAIL_DIE."");
             }

             
    //print success message and redirect browser
             
    msg_redirect(""._NEW_PWD_SENT_TO_YOUR_EMAIL."","users.php","10");

             
    //this else for :  if($check == 1){
             
    }else{
                    
                    
    Forgot_pwd_form();
                    echo 
    "<center><font class=\"error\">"._WRONG_USEREMAIL."</font></center><br>";
                    
             }

    If there is a better way of doing this please advise as I would like to understand HTML email as I am working on a newsletter script that uses this same structure.
    If it works don't fix it. If it's broke fix it.
    He who knows all is the smartest.
    He who doesn't know anything isn't dumbest.

  2. #2
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If its MD5 you will have to use a reset password script. More work but better security when using MD5.
    Have a good day.

  3. #3
    SitePoint Member digitalfiz's Avatar
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried just a blank php script with only the mail function in it to test if mail() is working properly on your server?

    PHP Code:
    <?php

    mail
    ('your@email.com''My test subject''My Test Email');

    ?>
    The code above should help you. If that fails you need to contact your host to find out why you cant send emails anymore. Chances are they upgraded a few other things not just php.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •