Jump to content

Recommended Posts

I am having a problem with my php mail () function I have one page that works and one that doesn't the code is below if anyone can see the problem or can think of a problem please help me out thank you so much......

 

Code That Works...

 

if ($submit)

{

if ($terms == 'disagree')

{

die ('If you do not agree to the Terms & Conditions than you are not permited to have an account on College Boox Store.');

}

if ($terms == 'agree')

{

//open database

$connect = mysql_connect("db","user","pass") or die("Not connected");

mysql_select_db("db") or die("could not log in");

 

$namecheck = mysql_query("SELECT username FROM TABLE*** WHERE username='$username'");

$count = mysql_num_rows($namecheck);

if ($count!=0)

{

die("Username already taken please try again.");

}

function check_email_address($email)

{

  // First, we check that there's one @ symbol,

// and that the lengths are right.

  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))

  {

  // Email invalid because wrong number of characters

    // in one section or wrong number of @ symbols.

  die ("please enter a valid email address!");

}

}

// check for existance

if($username&&$password&&$checkpassword&&$email&&$school)

{

// check if passwords match

if ($password==$checkpassword)

// check username and email lentgh

if (strlen($username)>25|| strlen($email)>35||strlen($school)>30)

{

echo "25/30 Character limit.";

}

else

// check password length

if (strlen($password)>25||strlen($password)<6)

{

die ("Password must be between 6 and 25 characters.");

}

else

{

// register user

echo "";

 

// open database

$connect = mysql_connect("db","user","pass") or die("Not connected");

mysql_select_db("db") or die("could not log in");

// generate random numbers for activation

$random = rand(23456789,98765432);

$queryreg = mysql_query("INSERT INTO TABLE** Values ('','$firstname','$lastname','$username','$school','$password','$email','$date','$random','0')");

 

$lastid = mysql_insert_id ();

//send activation email

$to = "[email protected]";

$subject = "Activate Account";

$headers = "From:$email";

$server = "smtp.gmail.com";

 

ini_set("SMTP",$server);

 

$body = "Register $firstname,\n\n

Username = $username\n

www.Collegebooxstore.com/activate.php?id=$lastid&code=$random\n\n";

 

//function to send email

mail($to, $subject, $body, $headers);

}

}

}

else

die ("Passwords do not match.");

}

else

die ("Please fill in all fields.");

}

 

else

die ('Please read the Terms & Conditions and make sure you check I agree if in order to create an account.');

}

 

 

 

Code That Does Not Work...

 

 

if ($submit)

{

 

//existance check

if ($firstname&&$question)

{

 

//connect to database

$connect = mysql_connect(db","user","pass") or die("Not connected");

mysql_select_db("user") or die("could not log in");

 

//grab email from database

$query = "SELECT * FROM TABLE*** WHERE username='$username'";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

 

//set email to variable name

$email = $row['email'];

 

//set SMTP

$server = "smtp.gmail.com";

ini_set("SMTP",$server);

 

 

 

//setup variables

$to = "[email protected]";

$subject = "Activate Account";

$headers = "From:$email";

$server = "smtp.gmail.com";

 

ini_set("SMTP",$server);

 

$body = "Register $firstname,\n\n

Username = $username\n

www.Collegebooxstore.com/activate.php?id=$lastid&code=$random\n\n";

 

//function to send email

mail("[email protected]", $subject, $body, $headers);

 

}

 

else

die('Please make sure your filled in your first Name as well as a Question/Comment!');

}

Link to comment
https://forums.phpfreaks.com/topic/229139-php-mail-still-not-figured-out/
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.