这是围绕我要询问的部分的所有代码(请参阅本节下方的重点部分)。
if($register == "true") //Registration "checks out" okay
{
$gooddata['password'] = md5($gooddata['password']);
//This is where the information is saved to the database.
$query = "INSERT INTO member (username,password,votingdistrict,email,birthmonth,birthyear,city,state,zip5,registeredtovote)
VALUES ('$gooddata[username]','$gooddata[password]','$gooddata[votingdistrict]','$gooddata[email]','$gooddata[birthmonth]','$gooddata[birthyear]','$gooddata[city]','$gooddata[state]','$gooddata[zip5]','$gooddata[registeredtovote]')";
$result = mysqli_query(dbcxn('member'),$query)
or die("<h3 class=\"headertag\">Username or E-mail already exists. <a href=\"./register.php\">Try a different username</a> or <a href=\"./resetpassword.php\">reset your password</a></h3>\n</header>");
if($result)
{
$query = "SELECT vernumber FROM member WHERE username='$gooddata[username]'";
$result = mysqli_query(dbcxn('member'),$query)
or die("Could not find a verification number!");
if($result)
{
$preextract = mysqli_fetch_assoc($result);
extract($preextract);
$email = $gooddata['email'];
$subject = "Confirmation of Unipartisan registration for " . $gooddata['username'];
$message = wordwrap("Please click <a href=\"\">this link<a> to complete your registration.<br /> \n" .
"If you did not try to register with <a href=\"http://unipartisan.com\">Unipartisan.com</a> please disregard this e-mail or click here.",70);
$mailsent = mail($email,$subject,$message);
if($mailsent == true)
{
echo "An e-mail has been sent to you to complete your registration</h3>\n";
}
else
{
echo "The registration email failed to send</h3>\n";
}
}
}
echo "</header>\n";
echo "<article class=\"index\">\n";
echo " <h3>Return to the <a href=\"./index.php\">homepage</a></h3>\n";
echo "</article>\n";
}
我的问题是如何在注册成功完成后仍向用户发送电子邮件,但无需在同一个 .php 文件中执行此操作,也无需将该 .php 文件发送给用户。
我问的原因是因为 mail() 函数需要大量时间来处理,并且页面不会加载大约 30 秒。但是,该电子邮件实际上确实已成功发送。
以下是我所指的具体部分。
$email = $gooddata['email'];
$subject = "Confirmation of Unipartisan registration for " . $gooddata['username'];
$message = wordwrap("Please click <a href=\"\">this link<a> to complete your registration.<br /> \n" .
"If you did not try to register with <a href=\"http://unipartisan.com\">Unipartisan.com</a> please disregard this e-mail or click here.",70);
$mailsent = mail($email,$subject,$message);
if($mailsent == true)
{
echo "An e-mail has been sent to you to complete your registration</h3>\n";
}
我知道我可以为此使用 cronjob,但我只发现程序员试图按时间设置重复脚本,或者他们试图延迟脚本的情况。我仍然希望它立即运行,但我不想在与注册处理相同的文件中运行邮件功能,因为它会导致客户端出现丑陋的延迟。
我怎样才能在完成注册的同时做到这一点?
这是我的 PHP.ini 的相关部分。
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = ryan@unipartisan.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i -f ryan@unipartisan.com
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =