...

View Full Version : Can't get my register from to email me



samsfriend
08-14-2008, 04:58 PM
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
//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) != 0 ) {
$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:

// 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:

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$email>");

hinch
08-14-2008, 05:03 PM
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

samsfriend
08-14-2008, 05:22 PM
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:

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$email>");
to:

// 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

hinch
08-14-2008, 05:48 PM
i typically use the main function like this



$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


$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

samsfriend
08-14-2008, 05:53 PM
You my friend rock! It works now! Thanks so much for your help.
I forgot to add:

// 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!

hinch
08-14-2008, 06:04 PM
no problem I do stuff like that all the time so its understandable

govnosak
05-16-2009, 08:57 AM
then the above
$success = mail($EmailTo, $Subject, $Body (http://www.positivegenerics.com/generic-prozac-online.html), "From: <$email>");

should work fine

To hinch: thanks. Now the script works correctly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum