Problems with PHP Mail

Status
Not open for further replies.

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
Hey, i am having problems with my login system sending the emails to people, i am unsure of what could possibly be wrong, i am no PHP whiz, i downloaded this script from a website, got it working after i experienced a few errors, but i can't for the life of me figure out how to make it send an email, i know in the install file that sets up the settings, it asked me if i iwanted to use SMTP for emails, i said no, because i didn't know SMTP port or username or anything like that, could this be the problem, that SMTP is disabled in the PHP script settings? or should it still work? i dont actually get an error when it attempts to send the email, it says it's sent and i should check my inbox, but i never recieve the mail, any help would be appreciated, and if you need any other info, just ask, below is the PHP code i use for the register.php page which contains the send mail code.
PHP:
<?php
    require_once('settings.php');

    if ( array_key_exists ( '_submit_check', $_POST ) )
    {
        if ( $_POST['username'] != '' && $_POST['password'] != '' && $_POST['password'] == $_POST['password_confirmed'] && $_POST['email'] != '' && valid_email ( $_POST['email'] ) == TRUE )
        {
            if ( ! checkUnique ( 'Username', $_POST['username'] ) )
            {
                $error = 'Username already taken. Please try again!';
            }
            elseif ( ! checkUnique ( 'Email', $_POST['email'] ) )
            {
                $error = 'The email you used is associated with another user. Please try again or use the "forgot password" feature!';
            }
            else {        
                $query = $db->query ( "INSERT INTO " . DBPREFIX . "users (`Username` , `Password`, `date_registered`, `Email`, `Random_key`) VALUES (" . $db->qstr ( $_POST['username'] ) . ", " . $db->qstr ( md5 ( $_POST['password'] ) ).", '" . time () . "', " . $db->qstr ( $_POST['email'] ) . ", '" . random_string ( 'alnum', 32 ) . "')" );
                
                $getUser = "SELECT ID, Username, Email, Random_key FROM " . DBPREFIX . "users WHERE Username = " . $db->qstr ( $_POST['username'] ) . "";
        
                if ( $db->RecordCount ( $getUser ) == 1 )
                {            
                    $row = $db->getRow ( $getUser );
                    
                    $subject = "Activation email from " . DOMAIN_NAME;

                    $message = "Dear ".$row->Username.", this is your activation link to join our website. In order to confirm your membership please click on the following link: <a href=\"" . APPLICATION_URL . "confirm.php?ID=" . $row->ID . "&key=" . $row->Random_key . "\">" . APPLICATION_URL . "confirm.php?ID=" . $row->ID . "&key=" . $row->Random_key . "</a> <br /><br />Thank you for joining";
                    
                    if ( send_email ( $subject, $row->Email, $message ) ) {
                        $msg = 'Account registered. Please check your email for details on how to activate it.';
                    }
                    else {
                        $error = 'I managed to register your membership but failed to send the validation email. Please contact the admin at ' . ADMIN_EMAIL;
                    }
                }
                else {
                    $error = 'User not found. Please contact the admin at ' . ADMIN_EMAIL;
                }
            }                            
        }
        else {        
            $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match one another.';    
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>roScripts.com - PHP Login System With Admin Features</title>
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
<!--
                     ____                               __
                    /\  _`\                  __        /\ \__
          _ __   ___\ \,\L\_\    ___   _ __ /\_\  _____\ \ ,_\   ____
         /\`'__\/ __`\/_\__ \   /'___\/\`'__\/\ \/\ '__`\ \ \/  /',__\
         \ \ \//\ \L\ \/\ \L\ \/\ \__/\ \ \/ \ \ \ \ \L\ \ \ \_/\__, `\
          \ \_\ \____/\ `\____\ \____\ \_\  \ \_\ \ ,__/\ \__\/\____/
           \/_/ \/___/  \/_____/\/____/ \/_/   \/_/\ \ \/  \/__/\/___/
                                                    \ \_\
                                                     \/_/
                                                Making your world easy
-->
</head>

<body>
    <div id="log">
<?php    if ( isset ( $error ) )    { echo '            <p class="error">' . $error . '</p>' . "\n";    }    ?>
<?php    if ( isset ( $msg ) )    { echo '            <p class="msg">' . $msg . '</p>' . "\n";    } else {//if we have a mesage we don't need this form again.?>
    </div>

    <div id="container" style="width:230px;">
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        <input type="hidden" name="_submit_check" value="1"/> 
            
        <label for="username">Username</label>
        <input class="input" type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" />
        
        <label for="password">Password</label>
        <input class="input" type="password" id="password" name="password" size="32" value="" />
        
        <label for="password_confirmed">Re-Password</label>
        <input class="input" type="password" id="password_confirmed" name="password_confirmed" size="32" value="" />
        
        <label for="email">Email</label>
        <input class="input" type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" />
        
        <input type="image" name="register" value="register"  class="submit-btn" src="images/btn.gif" alt="submit" title="submit" />
        <div class="clear"></div>
    </form>
    </div>
<? } ?>
</body>

</html>
 
Messages
341
Reaction score
0
Points
0
Do You Have PHP v2? Also x10 includes free (Or paid) SMTP email. Just Login to cPanel it is under the email section.
 
Last edited:

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
Yeah, it finished upgrading almost 2 days ago now, so i know that's not the problem, could it be the email it's trying to use is not configured right?
Edit:
Well, thats the thing, in the php config i disabled SMTP, and i am using the x10hosting email, so would i be right in saying that i need to enable SMTP to get it working?
 
Last edited:

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
If the script only works with SMTP then you'll need to use SMTP. The code you pasted does not include the function that actually sends the mail. It is calling function "send_email" which is a function that they made that must be included in another file.
 

Jarryd

Community Advocate
Community Support
Messages
5,534
Reaction score
43
Points
48
Yeah, it is, i just looked then, and found it, also i fixed a bit of the code, and voila it works without SMTP (using the script send function) =] Thanks for the help.
 
Status
Not open for further replies.
Top