如何发送验证电子邮件进行注册?

时间:2019-01-09 11:11:36

标签: php email

我最近开始使用php,所以我需要您的帮助。 我创建了一个联系表单,可以在有人提交后向我发送电子邮件,但是我又如何将电子邮件副本或新电子邮件发送给提交者呢?

谢谢。

这是我在用户输入电子邮件的html代码:

<div class="row">
    <div class="col-md-6">
        <div class="form-group">
            <label for="form_email">Email </label>
            <input id="form_email" type="email" name="email" class="form-control" placeholder="">
            <div class="help-block with-errors"></div>
        </div>
    </div>

这是向我发送电子邮件的php代码:

<?php
$from = 'Someone <registration@registration.gr>';

// an email address that will receive the email with the output of the form
$sendTo = 'me <me@wxample.com>';

// subject of the email
$subject = 'Subject';

// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Ονομα', 'surname' => 'Επίθετο', 'need' => 'Need', 'title' => 'Τίτλος','specialty' => 'Ειδικότητα','foreas' => 'Φορέας','country' => 'Χώρα','city' => 'Πόλη','area' => 'Περιοχή','address' => 'Διευθυνση','tk' => 'T.K','tergasias' => 'Tηλ.Εργασίας','toikias' => 'Tηλ.Οικίας','mobile' => 'Κινητό','fax' => 'Φαξ','email' => 'Email'); 

// message that will be displayed when everything is OK :)
$okMessage = 'Successfull';

// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';

1 个答案:

答案 0 :(得分:0)

首先需要将请求发送到php文件,例如,您通过 GET 方法以参数email=xyz@xyz.in发送

在php文件上生成一个随机数,并通过电子邮件保存到表中

您可以通过-

生成随机数
$randomcode=rand(100000,999999);

在这里我将其保存到名为随机码的变量

现在我们可以拍摄生成网址的电子邮件

$randomcode=rand(100000,999999);
$email=$_GET['email'];// storing email into a variable
$tempMail="verification@domain.com"; // --display on user email account
$to =$email;
$email_subject = "Verification of Email"; // you can enter anything else
$email_body = "http://www.somedomain.com/verifyemail.php?email=$email&code=$randomcode ,click above link to verify email";
$headers = "From: $tempMail\n"; 
$headers .= "Reply-To: $tempMail";
$check=false;
// now we will send mail
$check = mail($to,$email_subject,$email_body,$headers);
if($check){ //if success 
          }else{}

现在您需要创建一个php文档来验证该电子邮件,例如上面用作 verifyemail.php 的示例,其中php脚本将检查该随机数是否存储在表中... < / p>

现在用户将收到一封包含url的电子邮件,当他单击该 verifyemail.php 时将验证数据库中是否存在这些电子邮件,如果是,则验证成功