Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Can't get my register from to email me

    My register form works and acts the way it's suppose to but for the life of me I can't get it to email that someone has registered. Here's the script:
    PHP Code:
    <?php
        
    //Start session
        
    session_start();
        
        
    //Array to store validation errors
        
    $errmsg_arr = array();
        
        
    //Validation error flag
        
    $errflag false;
        
        
    //Connect to mysql server
        
    $link mysql_connect("database","username","password");
        if(!
    $link) {
            die(
    'Failed to connect to server: ' mysql_error());
        }
        
    //Select database
        
    $db mysql_select_db("database");
        if(!
    $db) {
            die(
    "Unable to select database");
        }
        
        
    //Function to sanitize values received from the form. Prevents SQL injection
        
    function clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
        
        
    // get posted data into local variables
        
    $EmailFrom Trim(stripslashes($_POST['email'])); 
        
    $EmailTo "me@mydomain.com";
        
    $Subject "New register";
        
    $fname Trim(stripslashes($_POST['FirstName'])); 
        
    $lname Trim(stripslashes($_POST['LastName'])); 
        
    $email Trim(stripslashes($_POST['email'])); 
        
    $login Trim(stripslashes($_POST['Login Name'])); 
        
    $IP=$_SERVER['REMOTE_ADDR'];    
        
               
    //Sanitize the POST values
        
    $fname clean($_POST['fname']);
        
    $lname clean($_POST['lname']);
        
    $email clean($_POST['email']);
        
    $login clean($_POST['login']);
        
    $password clean($_POST['password']);
        
    $cpassword clean($_POST['cpassword']);
        
        
    //Input Validations
        
    if($fname == '') {
            
    $errmsg_arr[] = 'First name missing';
            
    $errflag true;
        }
        if(
    $lname == '') {
            
    $errmsg_arr[] = 'Last name missing';
            
    $errflag true;
        }
             if(
    $email == '') {
                    
    $errmsg_arr[] = 'Email missing';
                    
    $errflag true;
        }
             if(
    $email == 'spammer@spammer.com'|| $email == "spammer2@spammer.com") {
                    
    $errmsg_arr[] = 'Sorry, you have been blocked from this service';
                    
    $errflag true;
        }
        if(
    $login == '') {
            
    $errmsg_arr[] = 'Login ID missing';
            
    $errflag true;
        }
        if(
    $password == '') {
            
    $errmsg_arr[] = 'Password missing';
            
    $errflag true;
        }
        if(
    $cpassword == '') {
            
    $errmsg_arr[] = 'Confirm password missing';
            
    $errflag true;
        }
        if( 
    strcmp($password$cpassword) != ) {
            
    $errmsg_arr[] = 'Passwords do not match';
            
    $errflag true;
        }
        
        
    //Check for duplicate login ID
        
    $qry "SELECT count(*) AS c FROM members WHERE login='$login'";
        
    $result mysql_query($qry);
        if(
    $result) {
            
    $result_array mysql_fetch_assoc($result);
            if(
    $result_array['c'] > 0) {
                
    $errmsg_arr[] = 'Login ID already in use';
                
    $errflag true;
            }
            @
    mysql_free_result($result);
        }
        else {
            die(
    "Query failed");
        }
        
        
    //If there are input validations, redirect back to the registration form
        
    if($errflag) {
            
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
            
    session_write_close();
            
    header("location: register-failed.html");
            exit();
        }
     
        
    //Create INSERT query
        
    $qry "INSERT INTO members(firstname, lastname,email, login, passwd) VALUES('$fname','$lname','$email','$login','".md5($_POST['password'])."')";
        
    $result mysql_query($qry);
        
    //Check whether the query was successful or not
        
    if($result) {
            
    header("location: register_waiting.html");
            exit();
        }else {
            die(
    "Query failed");

        }
        
    // send email 
        
    $success mail($EmailTo$Subject$Body"From: <$email>");?>
    I've tried it a couple of diiferent ways, i am sure it's an easy soultion, I just can't figure out what I doing wrong.
    This is the part that is not working:
    PHP Code:
    // get posted data into local variables
        
    $EmailFrom Trim(stripslashes($_POST['email'])); 
        
    $EmailTo "me@mydomain.com";
        
    $Subject "New register";
        
    $fname Trim(stripslashes($_POST['FirstName'])); 
        
    $lname Trim(stripslashes($_POST['LastName'])); 
        
    $email Trim(stripslashes($_POST['email'])); 
        
    $login Trim(stripslashes($_POST['Login Name'])); 
        
    $IP=$_SERVER['REMOTE_ADDR']; 
    And this:
    PHP Code:
    // send email 
        
    $success mail($EmailTo$Subject$Body"From: <$email>"); 
    Last edited by samsfriend; 08-14-2008 at 05:00 PM.

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    its redirecting to header("location: register_waiting.html"); before it gets to the email send bit move it above the if statement and it should work
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts
    That worked! It emailed me but all I know is the email address, the email didn't post the info it was suppose to. Any thoughts?

    Edited to say:
    I thought maybe the issuse was that I had $body

    so I changed it from:
    PHP Code:
    // send email  
        
    $success mail($EmailTo$Subject$Body"From: <$email>"); 
    to:
    PHP Code:
    // send email  
        
    $success mail($EmailTo$Subject$fname,$lname,$email$login$IP "From: <$email>"); 
    Now I get this:
    Parse error: syntax error, unexpected '"' in /homepages/27/d230656710/htdocs/web/html/register-exec.php on line 107
    Last edited by samsfriend; 08-14-2008 at 05:34 PM. Reason: I thought maybe the issuse was that I had $body

  • #4
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    i typically use the main function like this

    PHP Code:
    $mailheader "From: $sendfromaddress\r\nContent-type: text/html\r\n"
    mail($sendtoaddress$subject$body$mailheader); 
    works every time and most similar to what you had at first.

    Only thing is in your code above I can't actually see where you set your body data if you want this data in your body then it'd be something like this
    PHP Code:
    $fname Trim(stripslashes($_POST['FirstName'])); 
    $lname Trim(stripslashes($_POST['LastName'])); 
    $email Trim(stripslashes($_POST['email'])); 
    $login Trim(stripslashes($_POST['Login Name'])); 
    $IP=$_SERVER['REMOTE_ADDR'];  

    $body $fname." ".$lname."\r\n".$email."\r\n".$login."\r\n".$IP
    then the above
    $success = mail($EmailTo, $Subject, $Body, "From: <$email>");

    should work fine
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • Users who have thanked hinch for this post:

    samsfriend (08-14-2008)

  • #5
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts
    You my friend rock! It works now! Thanks so much for your help.
    I forgot to add:
    PHP Code:
    // prepare email body text
        
    $Body "";
        
    $Body .= "FirstName: ";
        
    $Body .= $fname;
        
    $Body .= "\n";
        
    $Body .= "LastName: ";
        
    $Body .= $lname;
        
    $Body .= "\n";
        
    $Body .= "Email: ";
        
    $Body .= $email;
        
    $Body .= "\n";
        
    $Body .= "login name: ";
        
    $Body .= $login;
        
    $Body .= "\n";
        
    $Body .= $IP;
        
    $Body .= "\n"
    Talk about silly! Thank you so much for your time! If I had a cookie I would send you one!

  • #6
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    no problem I do stuff like that all the time so its understandable
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by hinch View Post
    then the above
    $success = mail($EmailTo, $Subject, $Body, "From: <$email>");

    should work fine
    To hinch: thanks. Now the script works correctly.


  •  

    Tags for this Thread

    Posting Permissions

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