By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,254 Members | 2,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,254 IT Pros & Developers. It's quick & easy.

send users activation Email for the new accounts

P: 22
I have this code (it's a form which will sign up new users and send them an email to active they account).

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.         if(isset($_POST['submited'])) {
  3.             $msg="";
  4.  
  5.             $RFname = clean_text($_POST['RFname']);
  6.             $RLname = clean_text($_POST['RLname']);
  7.             $USERname = clean_text($_POST['UserName']);
  8.             $USERpassword = $_POST['UserPass'];
  9.             $USERpassword2 = $_POST['UserPassConfirm'];
  10.             $USERemail = $_POST['UserEmail'];
  11.             $USERwebsite = $_POST['WebSite'];
  12.             $hash = clean_text(md5(rand(0,1000)));
  13.  
  14.             if($USERpassword !== $USERpassword2) {
  15.             $msg = "<span class='errorMessges'>Confirm passwords did not match</span>";
  16.             }
  17.  
  18.             elseif($check=$db->query("select 1 from loginaccess where Email ='".$USERemail."'")){
  19.             if(mysqli_num_rows($check) > 0 ) {
  20.                 $msg = "<span class='errorMessges'>This email already taken</span>";
  21.             }
  22.  
  23.             elseif(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0){
  24.             $msg = "<span class='errorMessges'>Human code verification invalid</span>";
  25.           }
  26.  
  27.             else{
  28.                 $putData = " insert into loginaccess (id, FUname, LUname, Uname, Pword, Email, Website, hash) value ('', '$RFname', '$RLname', '$USERname', '$USERpassword', '$USERemail', '$USERwebsite', '$hash')";
  29.  
  30.                 $inputResult = $db -> query ($putData) or die ('$db->error');
  31.  
  32.                 if ($inputResult){
  33.                 $msg = "<span class='successMessgaes'>You have been successfully registered</span>";
  34.  
  35.                 // Send email to our user 
  36. $to='$USERemail'; 
  37. $subject ='Signup | Verification'; 
  38. $message =' 
  39.  
  40. Thanks for signing up! 
  41. Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below. 
  42.  
  43. ------------------------ 
  44. Username: '.$USERname.' 
  45. Password: '.$USERpassword.' 
  46. ------------------------ 
  47.  
  48. Please click this link to activate your account: 
  49.  
  50. http://www.yourwebsite.com/verify.php?email='.$USERemail.'&hash='.$hash.' 
  51.  
  52. ';
  53.  
  54. $headers = 'From:noreply@learning.com' . "\r\n"; 
  55. mail($to, $subject, $message, $headers);
  56.  
  57.                     }else{
  58.                         $msg = "<span class='errorMessges'>There was an error please try again later</span>";
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     ?>
  64.  
  65. <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
  66.  
  67. <table width="762" border="0" cellspacing="5" cellpadding="5">
  68.   <tr>
  69.     <td colspan="2" class="socialAndPeopleByName">Personal information</td>
  70.     <td colspan="2"><span class="socialAndPeopleByName">Account information</span></td>
  71.     </tr>
  72.   <tr>
  73.     <td width="91" class="registrationInfo"><span class="red">*</span> First name</td>
  74.     <td width="203"><label for="textfield"></label>
  75.       <span id="sprytextfield1">
  76.       <input name="RFname" type="text" class="registrationFeild" id="textfield" />
  77.       <span class="textfieldRequiredMsg"><br>
  78.       First name  is required.</span></span></td>
  79.     <td width="148"><span class="red">*</span><span class="registrationInfo"> User name</span></td>
  80.     <td width="255"><span id="sprytextfield5">
  81.       <input name="UserName" type="text" class="registrationFeild" id="textfield5" />
  82.       <span class="textfieldRequiredMsg"><br>
  83.       User name is required.</span></span></td>
  84.   </tr>
  85.   <tr>
  86.     <td class="registrationInfo"><span class="red">*</span> Last name</td>
  87.     <td><span id="sprytextfield2">
  88.       <input name="RLname" type="text" class="registrationFeild" id="textfield2" />
  89.       <span class="textfieldRequiredMsg"><br>
  90.       Last name is required.</span></span></td>
  91.     <td><span class="red">*</span><span class="registrationInfo"> Password</span></td>
  92.     <td><span id="sprypassword1">
  93.     <input name="UserPass" type="password" class="registrationFeild" id="textfield7" />
  94.     <span class="passwordRequiredMsg"><br>
  95.     Password is required.</span><span class="passwordMaxCharsMsg"><br>
  96.     Password can't be more then 20 letter</span><span class="passwordMinCharsMsg"><br>
  97.     Password can't be less then 6 letter</span></span></td>
  98.   </tr>
  99.   <tr>
  100.     <td class="registrationInfo"><span class="red">*</span> Valid email</td>
  101.     <td><span id="sprytextfield3">
  102.     <input name="UserEmail" type="text" class="registrationFeild" id="textfield3" />
  103.     <br>
  104.     <span class="textfieldRequiredMsg">Valid email is required.</span><span class="textfieldInvalidFormatMsg">Invalid email format.</span></span></td>
  105.     <td><span class="red">*</span><span class="registrationInfo"> Confirm Password</span></td>
  106.     <td><span id="sprypassword2">
  107.       <input name="UserPassConfirm" type="password" class="registrationFeild" id="textfield8" />
  108.       <span class="passwordRequiredMsg"><br>
  109.       Please confirm your password</span></span></td>
  110.   </tr>
  111.   <tr>
  112.     <td class="registrationInfo">Web site</td>
  113.     <td><span id="sprytextfield4">
  114.       <input name="WebSite" type="text" class="registrationFeild" id="textfield4" />
  115.       <br>
  116.       <span class="textfieldInvalidFormatMsg">Invalid format</span></span></td>
  117.     <td><span class="registrationInfo"><span class="red">*</span> Prove you are human</span></td>
  118.     <td><img src="includes/captcha.php?rand=<?php echo rand(); ?>" align="absmiddle" id='captchaimg' /> <a href="javascript: refreshCaptcha();"><img src="http://bytes.com/images/refreshIcon.jpg" alt="Refresh" width="18" height="25" border="0" align="absmiddle" /></a>      <input name="6_letters_code" type="text" class="registrationFeildSmall" id="6_letters_code" /></td>
  119.   </tr>
  120.   <tr>
  121.     <td colspan="3"><?php if(!empty($msg)) {echo $msg;} ?></td>
  122.     <td><input name="submited" type="submit" class="signUpItem" id="submited" value="" /></td>
  123.   </tr>
  124. </table>
  125. </form>

I just don't send any Emails when the user submit.
I think it should do,
any Idea will help here.
Apr 17 '12 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,035
First you should check for the return value of the function mail()
(see: http://www.php.net/manual/en/function.mail.php)

If this returns FALSE, no mail is send.
If this returns TRUE, is something in the config of your mailserver.
Apr 21 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.