Jump to content
MakeWebGames

Email Function help?


Nicholas

Recommended Posts

Hello everyone,

Right basically, I'm setting up a new system for my game Criminals Nightmare to prevent signup advertisers..

But I'm having some problems, it won't send the email to the Email Address inserted?

Can someone please help me find the cause?

 

if($them['email'] != '') {
 echo '<h3>Continuing Account Setup: what is your email address?</h3>
 <form action="prefs.php?act=AccountSetup&continue=1" method="post">
 <input type="text" name="email" size="25">
  <input type="submit" value="Confirm" />
 </form>';
 }
if(@abs(intval($_GET['continue'])) == 1) {
$check = mysql_query("SELECT email FROM players WHERE email='".mysql_real_escape_string($_POST['email'])."'");
if(mysql_num_rows($check)){
echo "<font color=red size=-1><center>E-Mail already in use.<br>Choose another one.</font><br />
<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Continue' />
 </form></center>";
exit($end->page());
}
$code = rand(1000000000,9000000000);
   mysql_query("INSERT INTO email_confirm VALUES ('{$them['UserID']}', '{$_POST['email']}', '$code', '0')");
$to = "".$_POST['email']."";
$subject = "Criminals Nightmare Email Activator";
$from = "[email protected]";
$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$message = '<html>
<body bgcolor="#999999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><table width="625" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td colspan="5" align="left" bgcolor="#999999" style="font-size: 10px;">
		   Learn more about the latest specials for Criminals Nightmare.</td>
	<td colspan="3" align="right" bgcolor="#999999" style="font-size: 10px;"></td>
</tr>
<tr>
	<td colspan="8">
		<img src="http://criminals-nightmare.com/mesi/topimage.jpg" width="635" height="137" alt="Criminals Nightmare" style="display: block;"></td>
</tr>
<tr>
	<td bgcolor="#999999" color="#232323" style="margin: 3px;">
<center><a target="_blank" href="http://www.criminals-nightmare.com/login.php" style="color: #373737; font-weight: bold;"><h3>LOGIN HERE</h3></a></center>
<center>__________________________________________________________________________________________</center><br />
Your code to activate your account is.. <h3><b>'.$code.'</b></h3><br /><br />
Enter this code inside the game on Account Setup.<br />
<center>__________________________________________________________________________________________</center>

	</td>
</tr>
</table></center>
</body>
</html>'; 
mail($to, $subject, $message, $headers); 
   echo "Email has been sent to (".mysql_real_escape_string($_POST['email']).")  with a code.<br /><form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Enter Code' />
 </form>";
 }

 

If you can help me, that be great :)

Thanks for reading, Nicholas.

Link to comment
Share on other sites

  • Replies 67
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

if(mail()) { mail sent } else { mail not sent }

Try that if the email is not in your spam folder.

do you mean like this?

 

if(mail()) {
$code = rand(1000000000,9000000000);
   mysql_query("INSERT INTO email_confirm VALUES ('{$them['UserID']}', '{$_POST['email']}', '$code', '0')");
$to = "".$_POST['email']."";
$subject = "Criminals Nightmare Email Activator";
$from = "[email protected]";
$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$message = '<html>
<body bgcolor="#999999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><table width="625" cellpadding="0" cellspacing="0" border="0">
   <tr>
       <td colspan="5" align="left" bgcolor="#999999" style="font-size: 10px;">
              Learn more about the latest specials for Criminals Nightmare.</td>
       <td colspan="3" align="right" bgcolor="#999999" style="font-size: 10px;"></td>
   </tr>
   <tr>
       <td colspan="8">
           <img src="http://criminals-nightmare.com/mesi/topimage.jpg" width="635" height="137" alt="Criminals Nightmare" style="display: block;"></td>
   </tr>
   <tr>
       <td bgcolor="#999999" color="#232323" style="margin: 3px;">
<center><a target="_blank" href="http://www.criminals-nightmare.com/login.php" style="color: #373737; font-weight: bold;"><h3>LOGIN HERE</h3></a></center>
<center>__________________________________________  ________________________________________________</center>
Your code to activate your account is.. <h3><b>'.$code.'</b></h3>
Enter this code inside the game on Account Setup.
<center>__________________________________________  ________________________________________________</center>

       </td>
   </tr>
</table></center>
</body>
</html>';
mail($to, $subject, $message, $headers);
   echo "Email has been sent to (".mysql_real_escape_string($_POST['email']).")  with a code.<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Enter Code' />
 </form>";
} else {
echo "Message wasn't sent";
exit($end->page());
}
Link to comment
Share on other sites

No, like this:

 

if($them['email'] != '') {
 echo '<h3>Continuing Account Setup: what is your email address?</h3>
 <form action="prefs.php?act=AccountSetup&continue=1" method="post">
 <input type="text" name="email" size="25">
  <input type="submit" value="Confirm" />
 </form>';
 }
if(@abs(intval($_GET['continue'])) == 1) {
$check = mysql_query("SELECT email FROM players WHERE email='".mysql_real_escape_string($_POST['email'])."'");
if(mysql_num_rows($check)){
echo "<font color=red size=-1><center>E-Mail already in use.Choose another one.</font>
<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Continue' />
 </form></center>";
exit($end->page());
}
$code = rand(1000000000,9000000000);
   mysql_query("INSERT INTO email_confirm VALUES ('{$them['UserID']}', '{$_POST['email']}', '$code', '0')");
$to = "".$_POST['email']."";
$subject = "Criminals Nightmare Email Activator";
$from = "[email protected]";
$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$message = '<html>
<body bgcolor="#999999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><table width="625" cellpadding="0" cellspacing="0" border="0">
   <tr>
       <td colspan="5" align="left" bgcolor="#999999" style="font-size: 10px;">
              Learn more about the latest specials for Criminals Nightmare.</td>
       <td colspan="3" align="right" bgcolor="#999999" style="font-size: 10px;"></td>
   </tr>
   <tr>
       <td colspan="8">
           <img src="http://criminals-nightmare.com/mesi/topimage.jpg" width="635" height="137" alt="Criminals Nightmare" style="display: block;"></td>
   </tr>
   <tr>
       <td bgcolor="#999999" color="#232323" style="margin: 3px;">
<center><a target="_blank" href="http://www.criminals-nightmare.com/login.php" style="color: #373737; font-weight: bold;"><h3>LOGIN HERE</h3></a></center>
<center>__________________________________________  ________________________________________________</center>
Your code to activate your account is.. <h3><b>'.$code.'</b></h3>
Enter this code inside the game on Account Setup.
<center>__________________________________________  ________________________________________________</center>

       </td>
   </tr>
</table></center>
</body>
</html>';
if(mail($to, $subject, $message, $headers))	{
	echo "Email has been sent to (".mysql_real_escape_string($_POST['email']).")  with a code.<form action='prefs.php?act=AccountSetup' method='post'>
  			<input type='submit' value='Enter Code' />
 			</form>";
}	else	{
	echo 'Email could not be sent.';
}
 }
Link to comment
Share on other sites

  • Have you created [email protected] an actual e-mail on your server?
  • Have you got the mail() function installed?
  • Can you send a blank e-mail using PHP to your e-mail?

No it's a made up one, so no one be able to reply to it anyways.

I used this system before to send weekly newsletters to everyone on the database and it worked fine.

Which is why I'm confused why it isn't working :s

I tried sending normal PHP version as wel with no html tags and it didn't work.

Link to comment
Share on other sites

No it's a made up one, so no one be able to reply to it anyways.

I used this system before to send weekly newsletters to everyone on the database and it worked fine.

Which is why I'm confused why it isn't working :s

I tried sending normal PHP version as wel with no html tags and it didn't work.

I believe, and I may be wrong, that you need to set it up, so they can talk to eachother :?

Link to comment
Share on other sites

Try something like this:

 

/* All the mail stuff
    - body
    - from
    - headers
    - subject
*/

if( mail( [parameters] ) )
  echo 'sent';
else
 echo 'failed';

so basically like this, if so.. still don't work.

if($them['email'] != '') {
 echo '<h3>Continuing Account Setup: what is your email address?</h3>
 <form action="prefs.php?act=AccountSetup&continue=1" method="post">
 <input type="text" name="email" size="25">
  <input type="submit" value="Confirm" />
 </form>';
 }
if(@abs(intval($_GET['continue'])) == 1) {
$check = mysql_query("SELECT email FROM players WHERE email='".mysql_real_escape_string($_POST['email'])."'");
if(mysql_num_rows($check)){
echo "<font color=red size=-1><center>E-Mail already in use.Choose another one.</font>
<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Continue' />
 </form></center>";
exit($end->page());
}
$code = rand(1000000000,9000000000);
$to = "".$_POST['email']."";
$subject = "Email Activator";
$from = "[email protected]";
$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$message = '<html>
<body bgcolor="#999999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><table width="625" cellpadding="0" cellspacing="0" border="0">
   <tr>
       <td colspan="5" align="left" bgcolor="#999999" style="font-size: 10px;">
              Learn more about the latest specials for Criminals Nightmare.</td>
       <td colspan="3" align="right" bgcolor="#999999" style="font-size: 10px;"></td>
   </tr>
   <tr>
       <td colspan="8">
           <img src="http://criminals-nightmare.com/mesi/topimage.jpg" width="635" height="137" alt="Criminals Nightmare" style="display: block;"></td>
   </tr>
   <tr>
       <td bgcolor="#999999" color="#232323" style="margin: 3px;">
<center><a target="_blank" href="http://www.criminals-nightmare.com/login.php" style="color: #373737; font-weight: bold;"><h3>LOGIN HERE</h3></a></center>
<center>__________________________________________  ________________________________________________</center>
Your code to activate your account is.. <h3><b>'.$code.'</b></h3>
Enter this code inside the game on Account Setup.
<center>__________________________________________  ________________________________________________</center>

       </td>
   </tr>
</table></center>
</body>
</html>';
if(mail($to, $subject, $message, $headers)) {
   echo "Email has been sent to (".mysql_real_escape_string($_POST['email']).")  with a code.<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Enter Code' />
 </form>";
} else {
   echo 'Email could not be sent.';
   }
 }
Link to comment
Share on other sites

so basically like this, if so.. still don't work.
if($them['email'] != '') {
 echo '<h3>Continuing Account Setup: what is your email address?</h3>
 <form action="prefs.php?act=AccountSetup&continue=1" method="post">
 <input type="text" name="email" size="25">
  <input type="submit" value="Confirm" />
 </form>';
 }
if(@abs(intval($_GET['continue'])) == 1) {
$check = mysql_query("SELECT email FROM players WHERE email='".mysql_real_escape_string($_POST['email'])."'");
if(mysql_num_rows($check)){
echo "<font color=red size=-1><center>E-Mail already in use.Choose another one.</font>
<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Continue' />
 </form></center>";
exit($end->page());
}
$code = rand(1000000000,9000000000);
$to = "".$_POST['email']."";
$subject = "Email Activator";
$from = "[email protected]";
$headers  = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$message = '<html>
<body bgcolor="#999999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><table width="625" cellpadding="0" cellspacing="0" border="0">
   <tr>
       <td colspan="5" align="left" bgcolor="#999999" style="font-size: 10px;">
              Learn more about the latest specials for Criminals Nightmare.</td>
       <td colspan="3" align="right" bgcolor="#999999" style="font-size: 10px;"></td>
   </tr>
   <tr>
       <td colspan="8">
           <img src="http://criminals-nightmare.com/mesi/topimage.jpg" width="635" height="137" alt="Criminals Nightmare" style="display: block;"></td>
   </tr>
   <tr>
       <td bgcolor="#999999" color="#232323" style="margin: 3px;">
<center><a target="_blank" href="http://www.criminals-nightmare.com/login.php" style="color: #373737; font-weight: bold;"><h3>LOGIN HERE</h3></a></center>
<center>__________________________________________  ________________________________________________</center>
Your code to activate your account is.. <h3><b>'.$code.'</b></h3>
Enter this code inside the game on Account Setup.
<center>__________________________________________  ________________________________________________</center>

       </td>
   </tr>
</table></center>
</body>
</html>';
if(mail($to, $subject, $message, $headers)) {
   echo "Email has been sent to (".mysql_real_escape_string($_POST['email']).")  with a code.<form action='prefs.php?act=AccountSetup' method='post'>
  <input type='submit' value='Enter Code' />
 </form>";
} else {
   echo 'Email could not be sent.';
   }
 }

I believe he means send a blank mail, not with all this html and stuff.

Link to comment
Share on other sites

Last Attempt from me:

 

if($them['email'] != '')	{
?>
<h3>Continuing Account Setup: What is your email address?</h3>
<form action="prefs.php?act=AccountSetup&continue=1" method="post">
	<input type="text" name="email" />
	<input type="submit" value="Confirm" />
</form>
<?php
}
if(isset($_GET['continue']) && $_GET['continue'] == 1)	{
$check = mysql_query('SELECT `email` FROM `players` WHERE `email` = "'.mysql_real_escape_string($_POST['email']).'"');
if(mysql_num_rows($check))	{
?>
<div style="color: red;" align="center">
	Email already in use. Choose another one.<br />
	<form action="prefs.php?act=AccountSetup" method="post">
		<input type="submit" value="Continue" />
	</form>
</div>
<?php
	exit($h->endpage());
}
$code = mt_rand(1000000000, 9000000000);
$to = $_POST['email'];
$subject = 'Email Activator';
$from = 'Criminals Nightmare - No Reply<[email protected]>';
$headers = 'MIME-Version: 1.0rn';
$headers.= '\r\nContent-type: text/html; charset=utf8';
$headers.= 'From: '.$from.'\r\n';

$message = <<<EOF
<html>
<head>
	<title>Criminals Nightmare Account Activation</title>
</head>
<body bgcolor="#999" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	<center>
		<table width="600" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td colspan="5" align="left" bgcolor="#999" style="font-size: 10px;">   Learn more about the latest specials for Criminals Nightmare.</td>
				<td colspan="3" align="right" bgcolor="#999" style="font-size: 10px;"></td>
			</tr>
			<tr>
				<td colspan="8"><img src="http://criminals-nightmare.com/mesi/topimage.jpg" width="600" height="135" alt="Criminals Nightmare" style="display: block;" /></td>
			</tr>
			<tr>
				<td bgcolor="#999" color="#323232" style="margin: 3px;">
					<center>
						<a href="_blank" href="http://www.criminals-nightmare.com/login.php" style="color: #373737;"><strong><h3>LOGIN HERE</h3></strong></a>

						__________________________________________________________________________________________<br />
						Your code to activate your account is: <strong>{$code}</strong><br />
						Enter this code inside the game on Account Setup.
						__________________________________________________________________________________________
					</center>
				</td>
			</tr>
		</table>
	</center>
</body>
</html>
EOF;
if(mail($to, $subject, $message, $headers)) {
?>
	Email has been sent to "<?php echo $_POST['email']; ?>" with a code.<br />
	<form action="prefs.php?act=AccountSetup" method="post">
		<input type="submit" value="Enter Code" />
	</form>
<?php
}	else	{
	echo 'Email could not be sent.';
}
}

 

post up any errors and shall help you fix them :)

Also, you DONT need to have the account setup on your server. You can have [email protected] and it WILL work.

Alternatively, you can use: http://sourceforge.net/projects/phpmailer/

Edited by HauntedDawg
Link to comment
Share on other sites

s/DONT/sometimes/

s/WILL/might/

s/Form:/From:/

Form fixed to from.

DONT -> Sometimes.

Hmmmm, on 6 different server's, they all worked.

WILL -> Might.

Again, 6 different server's proved that the email address DOES NOT NEED TO EXIST on the server AT ALL

Those 6 Servers range from 2 dedicated servers, 2 shared hosting accounts & 2 cloud hosting accounts. All worked fine.

Link to comment
Share on other sites

6 servers? That many? I'll raise you 58.

And I suppose all odd numbers > 1 are prime?

Tested 3 : Yup, prime

Tested 5 : Yup, prime

Tested 7 : Yup, prime

Looks good to me...

Just because a few work does not mean they all will.

Even if a fake address is accepted at the local end (a lot of hosts allow essentially <anything>@your.domain), that does not mean that the mail will reach its destination. The mail server itself may simply not permit unknown MAIL FROM: <random>@your.domain which is perfectly legitimate assuming you follow the RFCs (2821 I think it is). Sender Policy Frameworks may also reject the address for at least 3 different reasons. Any intermediary mail server can reject the address as it sees fit as long as it provides a response back to the originating server; though of course PHP will never see that response. On Windows servers, the internals of PHP will erroneously report a malformed address for ANY type of response other than a 250 (OK); so mail servers being restarted, or under heavy load make PHP assume something other than what is actually happening. On *nix equipment, a <random>@domain.com is as far I can make out, simply not tested for by the mail() command or the stream handlers so you actually cannot tell if the local MTA has accepted the mail or not.

Link to comment
Share on other sites

Let me point out, that this was tested on 6 server's this morning, Which i doubt you ran accross 58 to test.

On another note. It's weird that for the past 3 year's, gmail, hotmail, yahoo & so many other people have received their email from email's such as <something>_verify(1-6)@domain.com, yet not a single person complained that they never received their email, not ONCE. This is including personal website's.

Now, what i do see commonly from sending emails with image's, is if you don't use HTML and just plain text and include more than 4 image's in your mail. The receiver's mail client will reject it, or mark it as spam (Commonly gmail). Apart from that, I've not once encountered an issue of the email account NEEDING to be created on the server.

Mind you, this is talking on a large scale system where over 100,000 emails are sent out weekly to verify their email address. Not one of them has came back to say "Oh hey, i signed up, but didnt get my verification email".

Across the 6 year's I've been working with PHP, I've not once come across the situation of having to specifically create the email address on the server.

Many people suggest it to be created, but speaking from experience, I've not once needed to.

Edited by HauntedDawg
Link to comment
Share on other sites

No, I didn't test it on 58 servers; that's how they are configured.

 

A programmer, and engineer and a manager were on their to a meeting when while driving down rather steep road, the brakes failed resulting in the engineer, who was driving, having to force the car to a sudden stop by the crash barriers.

Shaken, but not hurt, the 3 men who were anxious to reach their destination decided that some sort of repair was in order.

The manager suggested a meeting, proposing endless reams of drawings, discussions, mission statements and other mostly unhelpful comments.

The engineer suggested simply grabbing what tools could be found in the boot and "having a go".

The programmer however, suggested they push the car back up the hill and see if it happened again.

Personally, I dislike pushing things up hills especially when I already know the outcome.

Your 6 years experience not withstanding, if even one system were to reject your mail, then your statement would be at fault. And as RoZ seems to point out, I'm not the only who uses locked down systems. Is it really so hard to accept that mail servers may not accept random addresses? The big companies we know use sender policy frameworks to bypass this problem - you can even see that if you look at (certainly Google's) mail headers.

Just looking at the source of any of the current crop of half-decent mail servers its pretty apparent that they are designed to handle a huge swathe of different problems; and reject mail with messages such as

 

  • 550 mailbox rejected for policy reasons
  • 551 User not local; please try <forward-path>
  • 553 Requested action not taken: mailbox name not allowed

If you've never had to deal these, lucky you. But of course you wouldn't actually see them with the mail() command itself, as it cannot differentiate between errors at all on Windows boxes (returning instead as I've already pointed out - a "malformed address" error internally equating to a False at your level), while on *nix boxes it simply doesn't even bother to parse the output of the MTA.

It doesn't actually matter whether the servers I (or other people) use block unknown addresses intentionally, what matters is whether the OP can solve their specific problem; so can we concentrate on that rather than wasting time? If you won't accept what I've stated - so be it; I'm sure others can do their own research. *When* you run into problems, hopefully you will remember this and quickly see the solution.

@OP : In the mean time; using something like SwiftMailer might actually reveal the problem right away - or go down to sockets level yourself - I'm sure somebody will be delighted to show you how they work.

Link to comment
Share on other sites

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.   Paste as plain text instead

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