Jump to content

mail isnt actually being sent like it says


Flames

Recommended Posts

Well i have the code for registration and after a while got it to insert the information to the database. but not i found another problem the mail isnt being sent. the code is below i'd appreciate any help from anyone. (as a small side note, the javascript doesnt come up not a major issue though)

registration script

<?php

include("config.php");

mysql_select_db("something", $con);
global $status;
$status = "good";
$newpassword = mysql_real_escape_string($password);
$md5password = MD5($newpassword);
$newusername = mysql_real_escape_string($username);
$newerusername = strtolower($newusername);
$newemail = mysql_real_escape_string($email);
user_valid($username);
pass_valid($password);
email_valid($email);
$time = time();
$key = base64_encode($time);

function mail_verify($user, $password, $email, $hash, $key)
{
$to = $email;
$url = "http://somewhere/activate.php?hash=".$hash."&key=".$key;
$subject = "Verify Your Account For somewhere";
$message = "

Thank you for registering with somewhere.<br>
To finish your registration you will need to use the link below. <br>
".$url."
Or you can go to somewhere/activate.php to manually fill out the form with the information below. <br>
Hash:
".$hash." <br>
Key:
".$key." <br>
Your username is
".$newusername." <br>
Your password is
".$newpassword." <br>
If you didnt register just ignore this message and you will not recieve any further emails

";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: Someone <Automated Message Do Not Reply>' . "\r\n";
mail($to,$subject,$message,$headers);
}
function user_valid($user)
{
if(5 > strlen($user))
{
global $status;
$status = "bad";
echo "Your username must be longer than 5 characters <br />";
}
elseif(strlen($user) > 30)
{
global $status;
$status = "bad";
echo "Your username must be shorter or equal to 30 characters long <br />";
}
else
{
}
}

function pass_valid($pass)
{
if( 6 > strlen($pass))
{
global $status;
$status = "bad";
echo "Password must be longer than 5 characters <br />";
}
elseif(strlen($pass) > 32)
{
global $status;
$status = "bad";
echo "Password must be shorter or equal to 32 characters <br />";
}
else
{
}
}

function email_valid($mail)
{
if(6 > strlen($mail))
{
global $status;
$status = "bad";
echo "Email must be longer than 5 Characters long <br />";
}
elseif(strlen($mail) > 30)
{
global $status;
$status = "bad";
echo "Email must be shorter or equal to 30 characters long <br />";
}
else
{
}
}

if(!isset($reg) || $reg !== "something")
{
echo "Please use the registration form";
}
else
{
if($password != $password2)
{
global $status;
$status = "bad";
echo "Both passwords need to match <br />";
}

if($status != "good")
{
echo "<script = text/javascript> alert(you have failed to register)";
echo "<a href = 'register.php'> Go Back and try again </a>";
}
else
{
mysql_query("INSERT INTO Account (username, password, email, status, rank)VALUES ('$newusername', '$md5password', '$newemail', '0', '1')");
echo "INSERT INTO Account (username, password, email, status, rank)VALUES ('$newusername', '$md5password', '$newemail', '0', '1')";
mail_verify($newusername, $newpassword, $newemail, $md5password, $key);
echo $newusername ." ". $newpassword ." ". $newemail ." ". $md5password ." ". $key;
echo "<center>You have successfully registered </center> <br />";
echo "<center>An email has been sent to the email address provided you will need to activate your account before logging in </center> <br />";
echo "<center>Please <a href = 'login.php'>Login Here!</a> </center>";
echo mysql_error();
}}
?>

 

 

 

 

 

and this is the resend validation mail script also doesnt work, this might be to do with the mysql as well though.

 

<?php

include('config.php');
mysql_select_db("something", $con);
if(!isset($_POST['code']) || $_POST['code'] != 'something')
{
?>
<html>
<center>
Please enter your email address below.
<form name = "mail" method = "post" action = "http://somewhere/mail.php">
Email address:<input type = "text" size = "20" name = "email">
<input type = "hidden" name = "code" value = "14569">
<input type = "submit" value = "resend email">
<?php
}
else
{
function mail_verify($user, $password, $email, $hash, $key)
{
$to = $email;
$url = "http://somewhere/activate.php?hash=".$hash."&key=".$key;
$subject = "Verify Your Account For somewhere";
$message = "

Thank you for registering with somewhere.<br>
To finish your registration you will need to use the link below. <br>
".$url."
Or you can go to somewhere/activate.php to manually fill out the form with the information below. <br>
Hash:
".$hash." <br>
Key:
".$key." <br>
Your username is
".$user." <br>
If you didnt register just ignore this message and you will not recieve any further emails

";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: Somewhere <Automated Message Do Not Reply>' . "\r\n";
mail($to,$subject,$message,$headers);
}
$email = mysql_real_escape_string($_POST['email']);
$empty = "";
if(mysql_query("SELECT email FROM Account WHERE email = '$email'") == 0)
{
echo "The email you put was not found in the database. Please press the link below to try again.";
}
else
{
echo "<center> Email resent, please check your inbox</center>";
$user = mysql_query("select username from Account where email = '$email'");
echo $user;
$password = mysql_query("select password from Account where email = '$email'");
echo $password;
$time = mysql_query("select timestamp from Account where email = '$email'");
echo $time;
$key = base64_encode($time);
mail_verify($user, $empty, $email, $password, $key);
}
}
?>

 

any advice is much appriecated.

Link to comment
Share on other sites

I do a lot of tinkering with PHP and MYSQL and this is how I got my mail function to work when somone was regristiring at my site.

 

<? 
include ('includes/thacoheader.php');
//Create Form

$top_form = "<form method=\"post\" action=\"$_SERVER[php_SELF]\"> <br>
<table width=\"45%\" border=\"2\" cellspacing=\"2\" cellpadding=\"2\" bordercolor=\"#000000\" bgcolor=\"#CCCCCC\">
  <tr>
    <td colspan=\"2\">";

$form_block = "</td>
  </tr>
  <tr class=\"cellbg1\">
    <td><strong>Character Name:</strong></td>
    <td><input type=\"text\" name=\"Cname\" value=\"$_POST[Cname]\" size=30></td>
  </tr>
  <tr class=\"cellbg1\">
    <td><strong>Who recomended you:</strong></td>
    <td><input type=\"text\" name=\"recomend\" value=\"$_POST[recomend]\" size=30></td>
  </tr>
  <tr class=\"cellbg1\">
    <td><strong>Email Address:</strong></td>
    <td><input type=\"text\" name=\"email\" value=\"$_POST[email]\" size=30></td>
  </tr>
  <tr class=\"cellbg1\">
    <td><strong>Email Address Confirm:</strong></td>
    <td><input type=\"text\" name=\"email1\" value=\"$_POST[email1]\" size=30></td>
  </tr>
  <tr class=\"cellbg1\">
    <td><strong>Why do you want to join THACO:</strong></td>   
    <td><input type=\"textarea\" name=\"wjoin\" value=\"$_POST[wjoin]\" size=60></td>
  </tr>
  <tr class=\"cellbg1\">
    <td><strong>User Name:</strong></td>
    <td><input type=\"text\" name=\"login\" value=\"$_POST[login]\" size=30></td>
  </tr>
  <tr align=\"center\" valign=\"middle\" class=\"cellbg1\">
    <td colspan=\"2\">
      <input type=\"submit\" name=\"submit\" value=\"Send this form\">
      <input type=\"hidden\" name=\"op\" value=\"ds\">
      <input type=\"reset\" name=\"reset\" value=\"Reset\">
    </td>
  </tr>
</table>
</form>"; 
if ($_POST[op] != "ds") 
{ 
	// they need to see the form 
	echo "$top_form"."$form_block"; 
} 
else if ($_POST[op] == "ds") 
	{ 

//********************************Check to see if the form has been filled out not blank and if the fields match.***************************		

		if (($_POST['email']) != ($_POST['email1']))
			{
				$result = "$result"." <font color=red>Your emails do not match.</font><br>";
				$complete = "no";
			}

		if(empty($_POST['Cname']))
			{
				$result = "$result"." <font color=red>You must enter a character name so we can find you in game.</font><br>";
				$complete = "no";
			}

		if(empty($_POST['recomend']))
			{
				$result = "$result"." <font color=red>You must enter who recomended you to apply or NA</font><br>";
				$complete = "no";
			}

		if(empty($_POST['email']))
			{
				$result = "$result"." <font color=red>You left your email address blank.</font><br>";
				$complete = "no";
			}

		if(empty($_POST['wjoin']))
			{
				$result = "$result"." <font color=red>Please enter why you would like to join THACO</font><br>";
				$complete = "no";
			}

		if ($complete != "no") 
			{ 

				$custip = $_SERVER['REMOTE_ADDR'];
				$additional_headers = "From: newapplicant@thaczero.com\n";
				$toaddress = $_POST['email'];
				$subject = "Your Thaco application at thaczero.com";
				$mailcontent = "Here is the information that you provided our new application officer\n\r" 
							."Character Name: " . $_POST['Cname'] . "\n\r"
							."Who recomended you: " . $_POST['recomend'] . "\n\r"
							."Email address: " . $_POST['email'] . "\n\r"
							."Why do you want to join THACO: " . $_POST['wjoin'] . "\n\r"
							. "\n\r"
							."Helpfull Tips.\n\r"
							."1.  Go to http://thaczero.com/forum/  and register with the same user name you applid with.\n"
							. "\n\r"
							. "\n\r"
							."2.  Be patient as or new applicant processor has real life to deal with as well.  He or she will get in contact with you with in 72 hours.\n"
							."3.  Thank you for applying at Thaczero.com Please do not reply to this email as it is an email bot.\n"; 

				mail($toaddress, $subject, $mailcontent, $additional_headers);
				$custip = $_SERVER['REMOTE_ADDR'];
				$additional_headers = "From: newapplicant@thaczero.com\n";
				$toaddress = "sawchukg@cox.net";
				$subject = "A new Thaco Applicant!";
				$mailcontent = "Here is the information that was provided by the applicant\n\r" 
							."Character Name: " . $_POST['Cname'] . "\n\r"
							."Who recomended you: " . $_POST['recomend'] . "\n\r"
							."Email address: " . $_POST['email'] . "\n\r"
							."Why do you want to join THACO: " . $_POST['email'] . "\n\r"
							. "\n\r";				
				mail($toaddress, $subject, $mailcontent, $additional_headers);
				ob_end_clean();
				header ("Location:applied.php");
			} 
			else if ($complete == "no") 
				echo "$top_form"."$result"."$form_block";
		}
?>

 

If I am way off base with this sorry just thoguth I would try and help so many others have helped me.  I also can not take credit for this mail function as I pieced it together with other online content to make it work.  I wish you the best.

Link to comment
Share on other sites

Unless there is an issue with the server executing the mail() function, here is what the problem ALWAYS is.

 

When you write the "from" part in the header, it HAS to be listed as from the domain it's being sent from. So you can't send an email that is "From: bob@gmail.com". It won't work. Ever. I guess if you have an unknowing host OR possibly your own server you can, but otherwise, change the "From:" to be from "whoever@YOURDOMAIN.com" and then test it.

Link to comment
Share on other sites

well i didnt have the email address existing before, but i made it and it still isnt working. so i think its the code.

 

though just if it makes any difference i have a .co.cc website connected to everydns which connects to 000webhost as well as connecting to google apps using custom cname and mx records.

to be sure i created the email address registration on both google apps and on 000webhost but no result.

please help.

Link to comment
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.