Php 如何修改formmail,使错误页面仍然发送电子邮件和重定向?
到目前为止,它提交电子邮件,但无论我做什么,它都不会重定向(服务器错误),我需要将其重定向到自定义错误页面 我将如何修改它以使其工作 原始代码:Php 如何修改formmail,使错误页面仍然发送电子邮件和重定向?,php,perl,forms,formmail,Php,Perl,Forms,Formmail,到目前为止,它提交电子邮件,但无论我做什么,它都不会重定向(服务器错误),我需要将其重定向到自定义错误页面 我将如何修改它以使其工作 原始代码: # If any error fields have been found, send error message to the user. # if (@error) { &error('missing_fields', @error) } 新代码: if (@error) { # Print HTTP header a
# If any error fields have been found, send error message to the user. #
if (@error) { &error('missing_fields', @error) }
新代码:
if (@error) { # Print HTTP header and opening HTML tags. #
print "Content-type: text/html\n\n";
print "<html>\n <head>\n";
# Print out title of page #
if ($Config{'title'}) { print "<title>$safeConfig{'title'}</title>\n" }
else { print "<title>Thank You</title>\n" }
print " </head>\n <body";
# Get Body Tag Attributes #
&body_attributes;
# Close Body Tag #
print ">\n <center>\n";
# Print custom or generic title. #
if ($Config{'title'}) { print "<h1>$safeConfig{'title'}</h1>\n" }
else { print "<h1>Thank You For Filling Out This Form</h1>\n" }
print "</center>\n";
print "Below is what you submitted to $safeConfig{'recipient'} on ";
print "$date<p><hr size=1 width=75\%><p>\n";
# If a sort order is specified, sort the form fields based on that. #
if ($Config{'sort'} =~ /^order:.*,.*/) {
# Set the temporary $sort_order variable to the sorting order, #
# remove extraneous line breaks and spaces, remove the order: #
# directive and split the sort fields into an array. #
$sort_order = $Config{'sort'};
$sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$sort_order =~ s/(\s+)?\n+(\s+)?//g;
$sort_order =~ s/order://;
@sorted_fields = split(/,/, $sort_order);
# For each sorted field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $sorted_field (@sorted_fields) {
local $sfname = &clean_html($sorted_field);
if ($Config{'print_blank_fields'} || $Form{$sorted_field} ne '') {
print "<b>$sfname:</b> $Form{$sorted_field}<p>\n";
}
}
}
# Otherwise, use the order the fields were sent, or alphabetic. #
else {
# Sort alphabetically if requested.
if ($Config{'sort'} eq 'alphabetic') {
@Field_Order = sort @Field_Order;
}
# For each form field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $field (@Field_Order) {
local $fname = &clean_html($field);
if ($Config{'print_blank_fields'} || $Form{$field} ne '') {
print "<b>$fname:</b> $Form{$field}<p>\n";
}
}
}
print "<p><hr size=1 width=75%><p>\n";
# Check for a Return Link and print one if found. #
if ($Config{'return_link_url'} && $Config{'return_link_title'}) {
print "<ul>\n";
print "<li><a href=\"$safeConfig{'return_link_url'}\">$safeConfig{'return_link_title'}</a>\n";
print "</ul>\n";
}
# Print the page footer. #
print <<"(END HTML FOOTER)";
<hr size=1 width=75%><p>
<center><font size=-1><a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 © 1995 - 2002 Matt Wright<br>
A Free Product of <a href="http://www.scriptarchive.com/">Matt's Script Archive, Inc.</a></font></center>
</body>
</html>
(END HTML FOOTER)
}
}
sub send_mail {
# Localize variables used in this subroutine. #
local($print_config,$key,$sort_order,$sorted_field,$env_report);
# Open The Mail Program
open(MAIL,"|$mailprog 1>&2");
print MAIL "To: $Config{'recipient'}\n";
print MAIL "From: $Config{'email'} ($Config{'realname'})\n";
# Check for Message Subject
if ($Config{'subject'}) { print MAIL "Subject: $Config{'subject'}\n\n" }
else { print MAIL "Subject: WWW Form Submission\n\n" }
print MAIL "Below is the result of your feedback form. It was submitted by\n";
print MAIL "$Config{'realname'} ($Config{'email'}) on $date\n";
print MAIL "-" x 75 . "\n\n";
if (@Print_Config) {
foreach $print_config (@Print_Config) {
if ($Config{$print_config}) {
print MAIL "$print_config: $Config{$print_config}\n\n";
}
}
}
# If a sort order is specified, sort the form fields based on that. #
if ($Config{'sort'} =~ /^order:.*,.*/) {
# Remove extraneous line breaks and spaces, remove the order: #
# directive and split the sort fields into an array. #
local $sort_order = $Config{'sort'};
$sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$sort_order =~ s/(\s+)?\n+(\s+)?//g;
$sort_order =~ s/order://;
@sorted_fields = split(/,/, $sort_order);
# For each sorted field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $sorted_field (@sorted_fields) {
if ($Config{'print_blank_fields'} || $Form{$sorted_field} ne '') {
print MAIL "$sorted_field: $Form{$sorted_field}\n\n";
}
}
}
# Otherwise, print fields in order they were sent or alphabetically. #
else {
# Sort alphabetically if specified: #
if ($Config{'sort'} eq 'alphabetic') {
@Field_Order = sort @Field_Order;
}
# For each form field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $field (@Field_Order) {
if ($Config{'print_blank_fields'} || $Form{$field} ne '') {
print MAIL "$field: $Form{$field}\n\n";
}
}
}
print MAIL "-" x 75 . "\n\n";
# Send any specified Environment Variables to recipient. #
foreach $env_report (@Env_Report) {
if ($ENV{$env_report}) {
print MAIL "$env_report: $ENV{$env_report}\n";
}
}
close (MAIL);
}
sub return_html {
# Local variables used in this subroutine initialized. #
local($key,$sort_order,$sorted_field);
# Now that we have finished using form values for any e-mail related #
# reasons, we will convert all of the form fields and config values #
# to remove any cross-site scripting security holes. #
local($field);
foreach $field (keys %Config) {
$safeConfig{$field} = &clean_html($Config{$field});
}
foreach $field (keys %Form) {
$Form{$field} = &clean_html($Form{$field});
}
# If redirect option is used, print the redirectional location header. #
if ($Config{'redirect'}) {
print "Location: $safeConfig{'redirect'}\n\n";
}
if(@error){#打印HTTP头和打开HTML标记#
打印“内容类型:text/html\n\n”;
打印“\n\n”;
#打印出页面的标题#
如果($Config{'title'}){print“$safeConfig{'title'}\n}
else{打印“谢谢”\n}
打印“\n\n\n”;
#打印自定义或通用标题#
如果($Config{'title'}){print“$safeConfig{'title'}\n}
else{打印“感谢您填写此表格”\n}
打印“\n”;
打印“以下是您提交给$safeConfig{'recipient'}的内容”;
打印“$date
\n”;
#如果指定了排序顺序,请根据该顺序对表单字段进行排序#
如果($Config{'sort'}=~/^order:.*,.*/){
#将临时$sort\u order变量设置为排序顺序#
#删除无关的换行符和空格,删除顺序:#
#指令并将排序字段拆分为数组#
$sort_order=$Config{'sort'};
$sort|u order=~s/(\s+\n)?,(\s+\n)?/,/g;
$sort\u order=~s/(\s+)\n+(\s+)//g;
$sort_order=~s/顺序:/;
@排序字段=拆分(/,/,$sort\u顺序);
#对于每个排序字段,如果它有值或打印空白#
#字段选项处于启用状态,打印表单字段和值#
foreach$sorted_字段(@sorted_字段){
本地$sfname=&clean\u html($sorted\u字段);
如果($Config{'print_blank_fields'}{124;}$Form{$sorted_field}ne''){
打印“$sfname:$Form{$sorted_field}\n”;
}
}
}
#否则,请使用字段的发送顺序或字母顺序#
否则{
#如果需要,按字母顺序排序。
if($Config{'sort'}eq'字母'){
@字段\顺序=排序@字段\顺序;
}
#对于每个表单字段,如果有值或打印空白#
#字段选项处于启用状态,打印表单字段和值#
foreach$字段(@field\u Order){
本地$fname=&clean_html($field);
如果($Config{'print_blank_fields'}}|$$Form{$field}ne''){
打印“$fname:$Form{$field}\n”;
}
}
}
打印“
\n”;
#检查返回链接,如果找到,则打印一个#
if($Config{'return\u link\u url'}&$Config{'return\u link\u title'}){
打印“\n”;
打印“- \n”;
打印“
\n”;
}
#打印页脚#
在第805行打印以下内容:
print "Location: " . &clean_html($Config{'missing_fields_redirect'}) . "\n\n";
&send_mail;
然后在表单中添加这个
<input type="hidden" name="missing_fields_redirect" value="http://www.example.com">
但正如评论所说,最好更新到TFMail(我很快会自己更新)@Jamie请查看并查看是否出现服务器错误,然后告诉我们这些错误是什么可能会有用。Jamie:matts版本存在严重的安全问题。Jamie:不要使用“local”,使用“my”。这样使用“local”是Perl 4的一个特性,而不是Perl 5。我赞同这里其他人的观点:请,请,请停止使用此代码。它确实很旧,很难处理,一开始就不是那么好,是一个安全问题,使糟糕的Perl定型观念永久化,并杀死小猫。