简体   繁体   English

如何使此电子邮件确认有效?

[英]How can I make this email confirmation work?

I've tried sending simple email using the mail function and it works. 我尝试使用邮件功能发送简单的电子邮件,并且可以正常工作。 But when I try to insert that to my program it won't. 但是,当我尝试将其插入到程序中时,不会。 Can someone tell me which part is wrong because I am pretty sure that it is not about xampp/sendmail config - I already tried 2 simple mailing programs and they all work except this one. 有人可以告诉我哪一部分是错误的,因为我非常确定这与xampp / sendmail配置无关-我已经尝试了2个简单的邮件发送程序,除了该程序外,它们都可以工作。

I tried my best to put(...) in place of unnecessary lines. 我尽力将(...)替换为不必要的行。 I think the problem is that, it can't go to the part where the prog reads the email function part? 我认为问题是,它不能转到编读取电子邮件功能部分的部分?

Here's my register.php: 这是我的register.php:

<?
session_start();
if(isset($_POST['register']))
{
    include('/class.register.php');

    $register = new Register();
if($register->process()) {
    header('location: login.php');
}
else  {
    $register->show_errors();
}
}


?>

<form method= "POST" action="<?=$_SERVER['PHP_SELF'];?>">
<table>
<tr><td>Username:</td><td><input type="text" name="ruser" required="required" /></td></tr>
<tr><td>Email:</td><td><input type="text" name="remail" required="required" /></td></tr>
<tr><td>Password:</td><td><input type="password" name="rpass" required="required" /></td></tr>
<tr><td>Title:</td><td><input type="text" name="rtitle" required="required" /></td></tr>
<tr><td>First Name:</td><td><input type="text" name="rfname" required="required" /></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="rlname" required="required" /></td></tr>
<tr><td>Mobile Number:</td><td><input type="text" name="rmobile" required="required" /></td></tr>


</table>

<input type="submit" name="register" value="Sign Up" />

</form>

Here's my class.register.php: 这是我的class.register.php:

<?

class Register
{

...

private $errors;  

public function __construct()
{
    $this->errors = array();

    ...;

    $this->token = $_POST['token'];
    $this->passmd5 = md5($this->password);

}

public function process()
  {
  if($this->valid_data() && $this->send_email())
$this->register();

return count($this->errors)? 0: 1;

}

public function filter($var)
{
    return preg_replace('/[^a-zA-z0-9@.]/','',$var);
}
public function user_exists()
{
    ...
} 

public function email_exists()
 ...

public function register()
{
    ...

}

public function show_errors()
 echo "<h3>Errors</h3>";

    foreach($this->errors as $key=>$value)
    echo $value."<br>";

public function valid_data()
...


public function send_email()
{

$from = 'jeremiah@citydelivery.ph';
$to = $_POST['remail'];
$subject = 'Registration confirmation';
$message = 'Please click the following link or copy and paste it
into your browser to complete the registration process: ';
$message .= 'http://example.com/confirm.php?u=';
$message .= urlencode($_POST['ruser']);
$message .= '&amp;t=';
$message .= urlencode($_POST['token']);

return mail($to, $subject, $message, $from);

}


}
?>

$this->send_email must be $this->send_email() $this->send_email必须是$this->send_email()

It is a function not a variable ;) 它是一个函数而不是一个变量;)

Also you use it in a statement, but send_mail() doesn't return anything, so it returns null, which ends up as false. 您也可以在语句中使用它,但是send_mail()不会返回任何内容,因此它返回null,最后返回false。

So do return mail($to, $subject, $message, $from); return mail($to, $subject, $message, $from); to fix that 解决这个问题

An if statement is execute in the order until it hits a false, when only using && (and) 仅使用&&(和)时 ,按顺序执行if语句,直到命中为假。

You have 你有

if($this->valid_token() && $this->valid_data() && $this->send_email())

So it is possible it never hits send_mail() because valid_data() is for example false. 因此有可能它永远不会命中send_mail()因为valid_data()例如是false。

To check this use var_dump($this->valid_token(), $this->valid_data(), $this->send_email() The first one that hits false is your problem to fix, and so one. 要检查此问题,请使用var_dump($this->valid_token(), $this->valid_data(), $this->send_email() 。第一个var_dump($this->valid_token(), $this->valid_data(), $this->send_email()错误是您要解决的问题,因此一个。

Use the following process function, it checks which on is the problem. 使用以下过程功能,它检查哪个是问题所在。 I recommend after it works to remove the die() functions 我建议在工作后删除die()函数

public function process()
  {
if($this->valid_token()) { die('token is the problem'); }
if($this->valid_data()) { die('valid data is the problem'); }
if($this->send_email()) { die('send email is the problem'); }

 if($this->valid_token() && $this->valid_data() && $this->send_email)
    $this->register();

return count($this->errors)? 0: 1;

}

I would like to thank all of you guys who contributed. 我要感谢所有贡献您的人。 I fixed the problem by creating another file which is sendmail.php and then have it included in my register.php. 我通过创建另一个文件sendmail.php解决了问题,然后将其包含在我的register.php中。

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

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