Avatar billede monitor Nybegynder
11. september 2000 - 13:32 Der er 12 kommentarer og
1 løsning

Mainscript ala matts...

Kan man ikke i php lave et script magen til det i matts script archive?? - et mail script som håndterer alle formularer osv....

En der kan lave sån et eller ved hvor der ligger et?
Avatar billede monitor Nybegynder
11. september 2000 - 13:38 #1
ups...i overskriften skulle der stå mailscript
Avatar billede limemedia Nybegynder
11. september 2000 - 13:40 #2
Jeg har et sådant liggende...

Faktisk to versioner... èn hvor du kan definere hvordan mailen skal se ud ved afsendelse (skal konfigureres med fil til hver form) samt én der samler alle informationer postet til scriptet og afsender.

Hvad er du interesseret i ?
Avatar billede limemedia Nybegynder
11. september 2000 - 13:50 #3
PHP port of Matt Wrights FormMail.pl WWW form to e-mail gateway.


<?php 
/* 
############################################################################## 
# PLEASE DO NOT REMOVE THIS HEADER!!! 
# 
# COPYRIGHT NOTICE 
# 
# FormMail.php v1.0 
# Copyright 2000,2001 Ai Graphics and Joe Lumbroso (c) All rights reserved. 
# Created 07/06/00  Last Modified 07/06/00 
# Joseph Lumbroso, http://www.aigraphics.com 
#                  http://www.dtheatre.com/formmail.php 
############################################################################## 
# 
# This cannot and will not be inforced but I would appreciate a link back 
# to any of these sites: 
# http://www.dtheatre.com 
# http://www.aigraphics.com 
# 
# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
# OTHER DEALINGS IN THE SOFTWARE. 
# 
############################################################################## 
*/ 

// parse the form and create the content string which we will send 
function parse_form($array) { 
    // build reserved keyword array 
  $reserved_keys[] =  \"require\"; 
  $reserved_keys[] =  \"email\"; 
  $reserved_keys[] =  \"recipient\"; 
  $reserved_keys[] =  \"subject\"; 
    // $reserved_keys[] = \"subject\"; 
  $reserved_keys[] =  \"bgcolor\"; 
  $reserved_keys[] =  \"text_color\"; 
  $reserved_keys[] =  \"link_color\"; 
  $reserved_keys[] =  \"vlink_color\"; 
  $reserved_keys[] =  \"alink_color\"; 
  $reserved_keys[] =  \"title\"; 
  $reserved_keys[] =  \"missing_fields_redirect\"; 
  $reserved_keys[] =  \"env_report\"; 
  if (count($array)) { 
      while (list($key, $val) = each($array)) { 
          // exclude reserved keywords 
        $reserved_violation = 0; 
        for ($ri=0; $ri<count($reserved_keys); $ri++) { 
            if ($key == $reserved_keys[$ri]) { 
              $reserved_violation = 1; 
            } 
        } 
          // prepare content 
        if ($reserved_violation != 1) 
            $content .=  \"\\t$key: $val\\n<br>\"; 
      } 
  } 
  return $content; 
} 

// mail the content we figure out in the following steps 
function mail_it($content, $subject, $email, $recipient) { 
        mail($recipient, $subject, $content,  \"From: $email\\r\\nReply-To: email\\r\\nX-Mailer: DT_formmail\"); 
} 

// take in the body building arguments and build the body tag for page display 
function build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color) { 
  if ($title) 
      echo  \"<title>$title</title>\"; 
  if (!$bgcolor) 
      $bgcolor =  \"#FFFFFF\"; 
  if (!$text_color) 
      $text_color =  \"#000000\"; 
  if (!$link_color) 
      $link_color =  \"#0000FF\"; 
  if (!$vlink_color) 
      $vlink_color =  \"#FF0000\"; 
  if (!$alink_color) 
      $alink_color =  \"#000088\"; 
  if ($background) 
      $background =  \"background=\\\"$background\\\"\"; 
  echo 
\"<body bgcolor=\\\"$bgcolor\\\" text=\\\"$text_color\\\" link=\\\"$link_color\\\" vlink=\\\"$vlink_color\\\" alink=\\\"$alink_color\\\" $background>\\n\\n\";

} 

// our mighty error function.. 
function print_error($reason,$type = 0) { 
  build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color); 
    // for missing required data 
  if ($type ==  \"missing\") { 
      ?> 
      The form was not submitted for the following reasons:<p> 
    <ul> <? 
    echo $reason. \"\\n\"; 
    ?></ul> 
    Please use your browser\'s back button to return to the form and try again. <? 
  } else {  // every other error 
      ?> 
      The form was not submitted because of the following reasons:<p> 
      <? 
  } 
  echo  \"<br><br>\\n\"; 
  exit; 
} 

// check for a recipient email address and check the validity of it 
if (!eregi( \"^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3}$\", $recipient)) { 
  print_error( \"<b>I NEED VALID RECIPIENT EMAIL ADDRESS TO CONTINUE</b>\"); 
} 

// handle the required fields 
if ($require) { 
    // seperate at the commas 
  $require = ereg_replace(  \" +\",  \"\", $require); 
  $required = split( \",\",$require); 
  for ($i=0;$i<count($required);$i++) { 
      $string = trim($required[$i]); 
      // check if they exsist 
      if((!(${$string})) || (!(${$string}))) { 
          // if the missing_fields_redirect option is on: redirect them 
        if ($missing_fields_redirect) { 
            header ( \"Location: $missing_fields_redirect\"); 
            exit; 
        } 
        $require; 
        $missing_field_list .=  \"<b>Missing: $required[$i]</b><br>\\n\"; 
      } 
  } 
    // send error to our mighty error function 
  if ($missing_field_list) 
      print_error($missing_field_list, \"missing\"); 
} 

// check the email fields for validity 
if (($email) || ($EMAIL)) { 
  $email = trim($email); 
  if ($EMAIL) 
      $email = trim($EMAIL); 
  if (!eregi( \"^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3}$\", $email)) { 
      print_error( \"your <b>email address</b> is invalid\"); 
  } 
  $EMAIL = $email; 
} 

// check zipcodes for validity 
if (($ZIP_CODE) || ($zip_code)) { 
  $zip_code = trim($zip_code); 
  if ($ZIP_CODE) 
      $zip_code = trim($ZIP_CODE); 
  if (!ereg( \"(^[0-9]{5})-([0-9]{4}$)\", $zip_code)) { 
      if (!ereg( \"(^[0-9]{5})\", $zip_code)) { 
        print_error( \"your <b>zip code</b> is invalid\"); 
      } 
  } 
} 

// check phone for validity 
if (($PHONE_NO) || ($phone_no)) { 
  $phone_no = trim($phone_no); 
  if ($PHONE_NO) 
      $phone_no = trim($PHONE_NO); 
  if (!ereg( \"(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)\", $phone_no)) { 
      print_error( \"your <b>phone number</b> is invalid\"); 
  } 
} 


// check phone for validity 
if (($FAX_NO) || ($fax_no)) { 
  $fax_no = trim($fax_no); 
  if ($FAX_NO) 
      $fax_no = trim($FAX_NO); 
  if (!ereg( \"(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)\", $fax_no)) { 
      print_error( \"your <b>fax number</b> is invalid\"); 
  } 
} 

// prepare the content 
$content = parse_form($HTTP_POST_VARS); 

// if the env_report option is on: get eviromental variables 
if ($env_report) { 
  $env_report = ereg_replace(  \" +\",  \"\", $env_report); 
  $env_reports = split( \",\",$env_report); 
  $content .=  \"------ eviromental variables ------\"; 
  for ($i=0;$i<count($env_reports);$i++) { 
      $string = trim($env_reports[$i]); 
      if ($env_reports[$i] ==  \"REMOTE_HOST\") 
        $content .=  \"REMOTE HOST: \".$REMOTE_HOST. \"\\n\"; 
      else if ($env_reports[$i] ==  \"REMOTE_USER\") 
        $content .=  \"REMOTE USER: \". $REMOTE_USER. \"\\n\"; 
      else if ($env_reports[$i] ==  \"REMOTE_ADDR\") 
        $content .=  \"REMOTE ADDR: \". $REMOTE_ADDR. \"\\n\"; 
      else if ($env_reports[$i] ==  \"HTTP_USER_AGENT\") 
        $content .=  \"BROWSER: \". $HTTP_USER_AGENT. \"\\n\"; 
  } 
} 


// if the subject option is not set: set the default 
if (!$subject) 
  $subject =  \"Form submission\"; 

// send it off 
mail_it($content, $subject, $email, $recipient); 

// if the redirect option is set: redirect them 
if ($redirect) { 
  header ( \"Location: $redirect\"); 
  exit; 
} else { 
  print  \"Thank you for your submission\\n\"; 
} 

// <----------    THE END    ----------> // 
?>
Avatar billede limemedia Nybegynder
11. september 2000 - 13:53 #4
Avatar billede monitor Nybegynder
11. september 2000 - 14:00 #5
ljweb>>> hmm...tror det er den sidstnævnte jeg skal bruge *ss* - den fungerer præcis ligesom matts ik?

den du har postet koderne på, det er den hvor man vælger udseendet når mailen blir sendt ik?

Kan man i scriptet bruge require o.s.v. i formene ligesom i  matts .pl script?
Avatar billede limemedia Nybegynder
11. september 2000 - 14:06 #6
monitor >> den jeg har postet koderne på skulle være en omskrivning af Matt\'s :D fandt den inde på WeberDev... Men den er utestet.

Avatar billede limemedia Nybegynder
11. september 2000 - 14:18 #7
http://www.dtheatre.com/formmail.php

Prøv dette link... Der er koderne, eksemplerne, dokumentationen m.v. - Nej den brygger ikke kaffe, meeennn :D
Avatar billede limemedia Nybegynder
11. september 2000 - 14:19 #8

Form Configuration
The action of your form needs to point towards this script (obviously).


ie:
<FORM ACTION=\"formmail.php\" METHOD=POST>

or if you are doing uploads
<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"formmail.php\" METHOD=POST>
Below is a list of form fields you can use and how to implement them.


Necessary Form Fields
There is only one form field that you must have in your form, for FormMail to work correctly. This is the recipient field.
Field:  recipient

Description:  This form field allows you to specify to whom you wish for your form results to be mailed. Most likely you will want to configure this option as a hidden form field with a value equal to that of your e-mail address.

Syntax:  <input type=hidden name=\"recipient\" value=\"email@your.host.com\">



--------------------------------------------------------------------------------


Optional Form Fields

Field:  subject

Description:  The subject field will allow you to specify the subject that you wish to appear in the e-mail that is sent to you after this form has been filled out. If you do not have this option turned on, then the script will default to a message subject: \"Form Submission\"

Syntax:  If you wish to choose what the subject is:
<input type=hidden name=\"subject\" value=\"Your Subject\">
To allow the user to choose a subject:
<input type=text name=\"subject\">


--------------------------------------------------------------------------------
Field:  email

Description:  This form field will allow the user to specify their return e-mail address. If you want to be able to return e-mail to your user, I strongly suggest that you include this form field and allow them to fill it in. This will be put into the From: field of the message you receive. The email address submitted will be checked for validity.

Syntax:  <input type=text name=\"email\">

--------------------------------------------------------------------------------
Field:  phone_no

Description:  This form field will allow the user to specify a phone number.
The phone number submitted will be checked for validity and must match one of the following formats.

123.123.1234
123-123-1234
(123)123.1234
(123)123-1234

Syntax:  <input type=text name=\"phone_no\">

--------------------------------------------------------------------------------

Field:  fax_no

Description:  This form field will allow the user to specify a fax number.
The phone number submitted will be checked for validity and must match one of the following formats.

123.123.1234
123-123-1234
(123)123.1234
(123)123-1234


Syntax:  <input type=text name=\"fax_no\">

--------------------------------------------------------------------------------

Field:  zip_code

Description:  This form field will allow the user to specify a zip code.
The zip code submitted will be checked for basic validity and must match one of the following formats.

12345
12345-1234


Syntax:  <input type=text name=\"zip_code\">

--------------------------------------------------------------------------------
Field:  redirect

Description:  If you wish to redirect the user to a different URL, rather than having them see the default response to the fill-out form, you can use this hidden variable to send them to a pre-made HTML page.

Syntax:  To choose the URL they will end up at:
<input type=hidden name=\"redirect\" value=\"http://your.host.com/to/file.html\">
To allow them to specify a URL they wish to travel to once the form is filled out:
<input type=text name=\"redirect\">


--------------------------------------------------------------------------------
Field:  required

Description:  You can now require for certain fields in your form to be filled in before the user can successfully submit the form. Simply place all field names that you want to be mandatory into this field. If the required fields are not filled in, the user will be notified of what they need to fill in, and a link back to the form they just submitted will be provided.
To use a customized error page, see \'missing_fields_redirect\'


Syntax:  If you want to require that they fill in the email and phone fields in your form, so that you can reach them once you have received the mail, use a syntax like:
<input type=hidden name=\"required\" value=\"email,phone\">


--------------------------------------------------------------------------------
Field:  env_report

Description:  Allows you to have Environment variables included in the e-mail message you receive after a user has filled out your form. Useful if you wish to know what browser they were using, what domain they were coming from or any other attributes associated with environment variables. The following is a short list of valid environment variables that might be useful:

REMOTE_HOST    - Sends the hostname making the
                  request.
REMOTE_ADDR    - Sends the IP address of the
                  remote host making the request.
REMOTE_USER    - If server supports authentication
                  and script is protected, this is
                  the username they have
                  authenticated as. *This is not
                  usually set.*
HTTP_USER_AGENT - The browser the client is using
                  to send the request.
There are others, but these are a few of the most useful. For more information on environment variables, see:
The CGI Resource Index: Documentation: Environment Variables


Syntax:  If you wanted to find the remote host and browser sending the request, you would put the following into your form:
<input type=hidden name=\"env_report\" value=\"REMOTE_HOST,HTTP_USER_AGENT\">


--------------------------------------------------------------------------------
Field:  file

Description:  Allows you to allow the user upload a file the sends you the file name.

REQUIRED

If you are using the file option it is very important to include the ENCTYPE in the form field
ie:
<FORM ENCTYPE=\"multipart/form-data\" ACTION=\"formmail.php\" METHOD=POST>
OPTIONS

MAX_FILE_SIZE - (case sensitive) hidden field must precede the file input field and its value is the maximum filesize accepted. The value is in bytes. In this destination file, the following variables will be defined upon a successful upload:

Syntax:  If you wanted to find the remote host and browser sending the request, you would put the following into your form:
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\">
<input type=\"hidden\" name=\"path_to_file\" value=\"/www/dir_where_file_goes/\">
<input type=\"file\" name=\"file\">



--------------------------------------------------------------------------------
Field:  title

Description:  This form field allows you to specify the title and header that will appear on the resulting page if you do not specify a redirect URL.

Syntax:  If you wanted a title of \'Feedback Form Results\':
<input type=hidden name=\"title\" value=\"Feedback Form Results\">


--------------------------------------------------------------------------------
Field:  missing_fields_redirect

Description:  This form field allows you to specify a URL that users will be redirected to if there are fields listed in the required form field that are not filled in. This is so you can customize an error page instead of displaying the default.
Syntax:  <input type=hidden name=\"missing_fields_redirect\" value=\"http://your.host.com/error.html\">

--------------------------------------------------------------------------------
Field:  background

Description:  This form field allow you to specify a background image that will appear if you do not have the redirect field set. This image will appear as the background to the form results page.

Syntax:  <input type=hidden name=\"background\" value=\"http://your.host.xxx/image.gif\">

--------------------------------------------------------------------------------
Field:  bgcolor

Description:  This form field allow you to specify a bgcolor for the form results page in much the way you specify a background image. This field should not be set if the redirect field is.

Syntax:  For a background color of White:
<input type=hidden name=\"bgcolor\" value=\"#FFFFFF\">


--------------------------------------------------------------------------------
Field:  text_color

Description:  This field works in the same way as bgcolor, except that it will change the color of your text.

Syntax:  For a text color of Black:
<input type=hidden name=\"text_color\" value=\"#000000\">


--------------------------------------------------------------------------------
Field:  link_color

Description:  Changes the color of links on the resulting page. Works in the same way as text_color. Should not be defined if redirect is.

Syntax:  For a link color of Red:
<input type=hidden name=\"link_color\" value=\"#FF0000\">


--------------------------------------------------------------------------------
Field:  vlink_color

Description:  Changes the color of visited links on the resulting page. Works exactly the same as link_color. Should not be set if redirect is.

Syntax:  For a visited link color of Blue:
<input type=hidden name=\"vlink_color\" value=\"#0000FF\">


--------------------------------------------------------------------------------
Field:  alink_color

Description:  Changes the color of active links on the resulting page. Works exactly the same as link_color. Should not be set if redirect is.

Syntax:  For a active link color of Blue:
<input type=hidden name=\"alink_color\" value=\"#0000FF\">


Any other form fields that appear in your script will be mailed back to you and displayed on the resulting page if you do not have the redirect field set. There is no limit as to how many other form fields you can use with this form, except the limits imposed by browsers and your server.



--------------------------------------------------------------------------------


Some of the possible uses of this script
You want to have a form that will be mailed to you, but aren\'t sure how to write the CGI script for it.
You are the webmaster of your site and want to allow users to use forms, but not to have their own cgi-bin directories, which can cause security risks to your system. You can set this script up and then allow all users to run off of it.
Want to have one script to parse all of your html forms and mail them to you.

--------------------------------------------------------------------------------


History
Version 2.0  8/30/00 -  Added Upload capabilities and File field etc...
Version 1.1a 7/15/00 -  Fixed the Required Fields Issue (thanks to Gard Paulsen for pointing it out).
Version 1.0a 7/10/00 -  This script was created and released.


--------------------------------------------------------------------------------


Final Comments
Thanks to Matt Wright from Matt\'s Script Archive for the original inspiration.
Avatar billede monitor Nybegynder
11. september 2000 - 14:24 #9
den virker perfekt ljweb :)
Avatar billede limemedia Nybegynder
11. september 2000 - 14:37 #10
:D
Avatar billede limemedia Nybegynder
11. september 2000 - 14:52 #11
Hvis det som sagt virker perfekt, må du jo ikke forglemme at acceptere mit svar... Jeg så at du var ny på sitet, så det var ikke sikkert du er klar over det.


PS. Det er måske knap så hensigtsmæssigt at bruge samtlige points på et spørgsmål, du skulle jo gerne have nogle points til at få besvaret flere spørgsmål. Med mindre du selvfølgelig er en \"ekspert\" :D

Avatar billede milo Nybegynder
11. september 2000 - 15:14 #12
ups sorry
Avatar billede monitor Nybegynder
11. september 2000 - 15:17 #13
mil>>> sorry hvad? jeg er ikke med...jeg accepterer dit svar nu ljweb
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester

IT-JOB

Netcompany A/S

IT Consultant

Forsvarsministeriets Materiel- og Indkøbsstyrelse

Cyberdivisionen søger sektionschef til HR, drift og udvikling i Hvidovre

Forsvarsministeriets Materiel- og Indkøbsstyrelse

Forretningsanalytiker til Forsvarets nye Digital Backbone