[英]Calling functions separate from each other works fine, executing one of them within the other does not
我一直在努力使用此电子邮件功能。 因此,基本上,我正在为一个个人项目在本地网站上工作,而我的电子邮件验证过程遇到了问题。 我有支持它的框架,但是没有发送电子邮件的方法。 这就是这个。
我有两个功能,“ register ”和“ registerEmail ”,我想一并使用。 “ 寄存器 ”不言自明; 它通过注册过程处理所有事情,而“ registerEmail ”发送用户获得的电子邮件,以便通过提供的链接激活其帐户。
当我尝试运行“registerEmail”的“ 注册 ”里面我的问题出现了,它根本不...注册。 “ 注册 ”功能按预期工作,并将用户添加到表中,但不“发送”任何电子邮件。 但是,' registerEmail '函数不是问题,因为如果我单独调用它,它就可以正常工作...我已经试图在绝望的情况下将这两个函数组合在一起(没有发送电子邮件),看来我在我的智慧尽头。
这里是提到的两个功能:
public function register($array){
....
all of the password and query stuff happens here
....
$stmt->bind_param('ssssssiss', $userName, $password, $salt, $email, $firstName, $lastName, $today, $activationCode, $active);
$stmt->execute();
}else{
printf("Prepared statement error: %s\n", $this->connection->error);
}
if($stmt->affected_rows == 1){
return 1;
}
$stmt->close();
#This part is the fault that I cannot pinpoint, it doesn't actually do anything.
$this->registerEmail($userName, $email, $firstName, $lastName, $activationCode);
}
}
public function registerEmail($userName, $email, $firstName, $lastName, $activateCode){
$to = $email;
$subject = 'Confirmation from Tangleball to ' . $userName;
$header = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '<html><head><title>Email verification</title></head><body>';
$message .= 'Hi ' . $firstName . $lastName . '! Your account, username "' . $userName . '", at place needs to be confirmed before you can log in, just <a href="http://127.0.0.1/place/index.php?activate=' . $activateCode . '">click here</a> to activate your place account. </body></html>';
#$message = wordwrap($message, 70, "\r\n");
$sentmail = mail($to, $subject, $message, $header);
}
我正在使用本地邮件服务器来“捕获”正在发送的电子邮件,因此,如果我调用我的registerEmail函数,它实际上会将电子邮件“发送”给“用户”。
我很茫然,有人可以戳我的东西吗?
您应该删除行return 1;
从
if($stmt->affected_rows == 1){
return 1;
}
它会工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.