Nicholas Posted September 20, 2012 Share Posted September 20, 2012 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. Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted September 20, 2012 Share Posted September 20, 2012 maybe it simply end up in the spam folder, did you checked? Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted September 20, 2012 Share Posted September 20, 2012 if(mail()) { mail sent } else { mail not sent } Try that if the email is not in your spam folder. Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 maybe it simply end up in the spam folder, did you checked? if the Junk folder is the spam folder then yes i already checked that aswell. Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 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()); } Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted September 20, 2012 Share Posted September 20, 2012 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.'; } } Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 I tried that it says the mail was sent, but I still haven't received the message in hotmail. I've made sure "[email protected]" was in my safe sender aswell, still no message? Why isn't it working? any other ideas? Quote Link to comment Share on other sites More sharing options...
sniko Posted September 20, 2012 Share Posted September 20, 2012 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? Quote Link to comment Share on other sites More sharing options...
Djkanna Posted September 20, 2012 Share Posted September 20, 2012 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? You can rule out the second, he's got it, he wouldn't have got as far as he is if he had not. Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 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. Quote Link to comment Share on other sites More sharing options...
sniko Posted September 20, 2012 Share Posted September 20, 2012 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 :? Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 I believe, and I may be wrong, that you need to set it up, so they can talk to eachother :? what do you mean? Quote Link to comment Share on other sites More sharing options...
sniko Posted September 20, 2012 Share Posted September 20, 2012 what do you mean? Set up the e-mail that you'll be using in your script, again, I may be wrong. Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 Set up the e-mail that you'll be using in your script, again, I may be wrong. just tried a hotmail email address i know works but still not came through. so it cant be nothing to do with that? Quote Link to comment Share on other sites More sharing options...
sniko Posted September 20, 2012 Share Posted September 20, 2012 Try something like this: /* All the mail stuff - body - from - headers - subject */ if( mail( [parameters] ) ) echo 'sent'; else echo 'failed'; Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 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.'; } } Quote Link to comment Share on other sites More sharing options...
Djkanna Posted September 20, 2012 Share Posted September 20, 2012 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. Quote Link to comment Share on other sites More sharing options...
Nicholas Posted September 20, 2012 Author Share Posted September 20, 2012 nope, tried it with $message = ''; but still got no email :s Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted September 21, 2012 Share Posted September 21, 2012 (edited) 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 September 21, 2012 by HauntedDawg Quote Link to comment Share on other sites More sharing options...
Octarine Posted September 21, 2012 Share Posted September 21, 2012 (edited) s/DONT/sometimes/ s/WILL/might/ s/Form:/From:/ Edited September 21, 2012 by Octarine Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted September 21, 2012 Share Posted September 21, 2012 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. Quote Link to comment Share on other sites More sharing options...
Octarine Posted September 21, 2012 Share Posted September 21, 2012 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. Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted September 21, 2012 Share Posted September 21, 2012 (edited) 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 September 21, 2012 by HauntedDawg Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 21, 2012 Share Posted September 21, 2012 My mail server wont send to an address that doesnt look up first. So a fake or incorrect email address wont lookup and thus email will not be sent. As that is how I setup the server. So on my server an email address most certainly needs to exist. Quote Link to comment Share on other sites More sharing options...
Octarine Posted September 21, 2012 Share Posted September 21, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.