简体   繁体   English

向用户发送新帐户的激活电子邮件

[英]send users activation Email for the new accounts

I have this code (it's a form which will sign up new users and send them an email to active they account). 我有此代码(这是一种表单,用于注册新用户并向他们发送电子邮件以激活他们的帐户)。

    <?php
        if(isset($_POST['submited'])) {
            $msg="";

            $RFname = clean_text($_POST['RFname']);
            $RLname = clean_text($_POST['RLname']);
            $USERname = clean_text($_POST['UserName']);
            $USERpassword = $_POST['UserPass'];
            $USERpassword2 = $_POST['UserPassConfirm'];
            $USERemail = $_POST['UserEmail'];
            $USERwebsite = $_POST['WebSite'];
            $hash = clean_text(md5(rand(0,1000)));

            if($USERpassword !== $USERpassword2) {
            $msg = "<span class='errorMessges'>Confirm passwords did not match</span>";
            }

            elseif($check=$db->query("select 1 from loginaccess where Email ='".$USERemail."'")){
            if(mysqli_num_rows($check) > 0 ) {
                $msg = "<span class='errorMessges'>This email already taken</span>";
            }

            elseif(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0){
            $msg = "<span class='errorMessges'>Human code verification invalid</span>";
          }

            else{
                $putData = " insert into loginaccess (id, FUname, LUname, Uname, Pword, Email, Website, hash) value ('', '$RFname', '$RLname', '$USERname', '$USERpassword', '$USERemail', '$USERwebsite', '$hash')";

                $inputResult = $db -> query ($putData) or die ('$db->error');

                if ($inputResult){
                $msg = "<span class='successMessgaes'>You have been successfully registered</span>";

                // Send email to our user 
$to='$USERemail'; 
$subject ='Signup | Verification'; 
$message =' 

Thanks for signing up! 
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below. 

------------------------ 
Username: '.$USERname.' 
Password: '.$USERpassword.' 
------------------------ 

Please click this link to activate your account: 

http://www.yourwebsite.com/verify.php?email='.$USERemail.'&hash='.$hash.' 

';

$headers = 'From:noreply@learning.com' . "\r\n"; 
mail($to, $subject, $message, $headers);

                    }else{
                        $msg = "<span class='errorMessges'>There was an error please try again later</span>";
                    }
                }
            }
        }
    ?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<table width="762" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td colspan="2" class="socialAndPeopleByName">Personal information</td>
    <td colspan="2"><span class="socialAndPeopleByName">Account information</span></td>
    </tr>
  <tr>
    <td width="91" class="registrationInfo"><span class="red">*</span> First name</td>
    <td width="203"><label for="textfield"></label>
      <span id="sprytextfield1">
      <input name="RFname" type="text" class="registrationFeild" id="textfield" />
      <span class="textfieldRequiredMsg"><br>
      First name  is required.</span></span></td>
    <td width="148"><span class="red">*</span><span class="registrationInfo"> User name</span></td>
    <td width="255"><span id="sprytextfield5">
      <input name="UserName" type="text" class="registrationFeild" id="textfield5" />
      <span class="textfieldRequiredMsg"><br>
      User name is required.</span></span></td>
  </tr>
  <tr>
    <td class="registrationInfo"><span class="red">*</span> Last name</td>
    <td><span id="sprytextfield2">
      <input name="RLname" type="text" class="registrationFeild" id="textfield2" />
      <span class="textfieldRequiredMsg"><br>
      Last name is required.</span></span></td>
    <td><span class="red">*</span><span class="registrationInfo"> Password</span></td>
    <td><span id="sprypassword1">
    <input name="UserPass" type="password" class="registrationFeild" id="textfield7" />
    <span class="passwordRequiredMsg"><br>
    Password is required.</span><span class="passwordMaxCharsMsg"><br>
    Password can't be more then 20 letter</span><span class="passwordMinCharsMsg"><br>
    Password can't be less then 6 letter</span></span></td>
  </tr>
  <tr>
    <td class="registrationInfo"><span class="red">*</span> Valid email</td>
    <td><span id="sprytextfield3">
    <input name="UserEmail" type="text" class="registrationFeild" id="textfield3" />
    <br>
    <span class="textfieldRequiredMsg">Valid email is required.</span><span class="textfieldInvalidFormatMsg">Invalid email format.</span></span></td>
    <td><span class="red">*</span><span class="registrationInfo"> Confirm Password</span></td>
    <td><span id="sprypassword2">
      <input name="UserPassConfirm" type="password" class="registrationFeild" id="textfield8" />
      <span class="passwordRequiredMsg"><br>
      Please confirm your password</span></span></td>
  </tr>
  <tr>
    <td class="registrationInfo">Web site</td>
    <td><span id="sprytextfield4">
      <input name="WebSite" type="text" class="registrationFeild" id="textfield4" />
      <br>
      <span class="textfieldInvalidFormatMsg">Invalid format</span></span></td>
    <td><span class="registrationInfo"><span class="red">*</span> Prove you are human</span></td>
    <td><img src="includes/captcha.php?rand=<?php echo rand(); ?>" align="absmiddle" id='captchaimg' /> <a href="javascript: refreshCaptcha();"><img src="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>
  </tr>
  <tr>
    <td colspan="3"><?php if(!empty($msg)) {echo $msg;} ?></td>
    <td><input name="submited" type="submit" class="signUpItem" id="submited" value="" /></td>
  </tr>
</table>
</form>

I just don't send any Emails when the user submit I think it should do any Idea please here. 用户提交时,我只是不发送任何电子邮件,我认为它应该在此处执行任何操作。


I changed the free hosting that I was using but still not sending confirm to users any help 我更改了正在使用的免费托管,但仍未向用户发送确认信息

Thanks 谢谢

Check the following properties in php.ini 检查php.ini中的以下属性

  • 'sendmail_path' 'sendmail_path'
  • 'sendmail_from' “ sendmail_from”

And set it properly. 并正确设置。

Thanks everybody I got my answer I had many mistakes in the sending email and this is the correct one. 谢谢大家,我的回答是正确的,我在发送电子邮件时遇到很多错误。

if ($inputResult){

$to = "$USERemail"; $subject = "Signup | Verification"; $email = "$UserEmail"; $message=' 
Thanks for signing up! 
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below. 

------------------------ 
Username: '.$USERname.' 
Password: '.$USERpassword.' 
------------------------ 

Please click this link to activate your account: 

http://www.yourwebsite.com/verify.php?email='.$USERemail.'&hash='.$hash.' 
'; 
$headers = "From: $UserEmail"; $sent = mail($to, $subject, $name, $message, $headers) ; if($sent) {print "<p style='color:#090'>Your mail was sent successfully</p>"; } else {print "We encountered an error sending your mail"; }
$msg = "<span class='successMessgaes'>You have been successfully registered</span>"; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM