mediengestalter.info
FAQ :: Mitgliederliste :: MGi Team

Willkommen auf dem Portal für Mediengestalter

Aktuelles Datum und Uhrzeit: Sa 20.04.2024 02:03 Benutzername: Passwort: Auto-Login

Thema: html-formular via php-script vom 27.11.2008


Neues Thema eröffnen   Neue Antwort erstellen MGi Foren-Übersicht -> Programmierung -> html-formular via php-script
Autor Nachricht
samuk
Threadersteller

Dabei seit: 01.06.2006
Ort: Upper-Eastside Helvetia
Alter: 48
Geschlecht: Männlich
Verfasst Do 27.11.2008 12:14
Titel

html-formular via php-script

Antworten mit Zitat Zum Seitenanfang

moinsen ihr

ich hab da ein irre komplexes html-formular gemacht, und möchte dies an eine mailadresse senden.
das ganze funktioniert auch schon, nur kommts noch chaosmässig beim empfänger an.

wie kann ich das nun am einfachsten sortieren, bzw, formatieren, ohne das ganze formular neu zu machen?

lieb dank. samuk
  View user's profile Private Nachricht senden
DOUBLE_G

Dabei seit: 29.08.2006
Ort: Erbach
Alter: 36
Geschlecht: Männlich
Verfasst Do 27.11.2008 12:29
Titel

Antworten mit Zitat Zum Seitenanfang

stell mal die mailer.php datei rein...
  View user's profile Private Nachricht senden
Anzeige
Anzeige
samuk
Threadersteller

Dabei seit: 01.06.2006
Ort: Upper-Eastside Helvetia
Alter: 48
Geschlecht: Männlich
Verfasst Do 27.11.2008 12:35
Titel

Antworten mit Zitat Zum Seitenanfang

das ist die vom oliver hitz:

Code:
<?php

/*
 * Copyright (C) 2005 Oliver Hitz <oliver@net-track.ch>
 *
 * $Id$
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

class FormMailClass
{
  var $version;
  var $sender;
  var $recipients;
  var $subject;
  var $intro;
  var $required;

  var $errorURL;
  var $followupURL;

  function FormMailClass()
  {
    $this->version = "0.1";
    $this->sender = null;
    $this->recipients = array();
    $this->subject = sprintf("formmail %s at %s", $this->version, $this->getScriptURL());
    $this->intro = sprintf("The following was entered into the form at\n%s", $this->getScriptURL());
    $this->required = array();
    $this->errorURL = null;
    $this->followupURL = null;
  }

  function fail($m, $c = 1)
  {
    printf("<html><title>formmail.php</title><body>%s</body></html>", $m);
    exit($c);
  }

  function setSender($s)
  {
    if (!$this->isEmail($s)) {
      $this->fail("Sender address '$s' is not a valid email address.");
    }
    $this->sender = $s;
  }

  function addRecipient($r)
  {
    if (!$this->isEmail($r)) {
      $this->fail("Recipient address '$r' is not a valid email address.");
    }
    $this->recipients[] = $r;
  }

  function setSubject($s)
  {
    $this->subject = $s;
  }

  function setIntro($i)
  {
    $this->intro = $i;
  }

  function setRequiredFields($req)
  {
    $this->required = array();
    foreach ($req as $r) {
      if (trim($r) != "") {
        $this->required[] = $r;
      }
    }
  }

  function setFollowupURL($u)
  {
    $this->followupURL = $this->absoluteURL($u);
  }

  function setErrorURL($u)
  {
    $this->errorURL = $this->absoluteURL($u);
  }

  function absoluteURL($r)
  {
    if (!ereg("^https?://", $r) && !ereg("^/", $r)) {
      $r = sprintf("%s%s",
              dirname($_SERVER["SCRIPT_NAME"]),
              $r);
    }
    if (!ereg("https?://", $r)) {
      if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
        $scheme = "https";
      } else {
        $scheme = "http";
      }
      $r = sprintf("%s://%s%s",
              $scheme,
              $_SERVER["HTTP_HOST"],
              $r);
    }
    return $r;
  }

  function getScriptURL()
  {
    return sprintf("http://%s%s", $_SERVER["HTTP_HOST"], $_SERVER["SCRIPT_NAME"]);
  }

  function isEmail($email)
  {
    // Ensure there is only one @ symbol and the parts have the
    // correct lengths
    if (!ereg("([^@]{1,64})@([^@]{1,255})", $email, $parts)) {
      return false;
    }

    // Split local part
    $local = explode(".", $parts[1]);

    // Check individual local parts
    foreach ($local as $l) {
      if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $l)) {
        return false;
      }
    }

    // Check if domain is an IP address
    if (ereg("^\[?[0-9\.]+\]?$", $parts[2])) {
      return true;
    }
   
    // Split domain part
    $domain = explode(".", $parts[2]);
   
    // Check individual domain parts
    foreach ($domain as $d) {
      // Since there are IDN's, nothing can be tested here anymore
      // except if there is an empty domain part (means that there
      // were two consecutive dots).
      if ($d == "") {
        return false;
      }
    }

    return true;
  }

  function process()
  {
    // Check if all data fields are available
    if ($this->sender == null) {
      $this->fail("Sender address not set.");
    }
    if (0 == count($this->recipients)) {
      $this->fail("No recipients are set.");
    }

    // Check if all required fields are set
    foreach ($this->required as $r) {
      if (empty($_POST[$r]) || trim($_POST[$r]) == "") {
        if ($this->errorURL != null) {
          header(sprintf("Location: %s", $this->errorURL));
          exit(0);
        } else {
          $this->fail(sprintf("Required field '%s' not set.", $r));
        }
      }
    }

    $boundary = md5(uniqid(time()));

    $h = array();
    $h[] = sprintf("X-Mailer: formmail.php %s at %s", $this->version, $this->getScriptURL());
    $h[] = "MIME-Version: 1.0";
    $h[] = sprintf("Content-Type: multipart/mixed; boundary=\"%s\"", $boundary);
    $h[] = sprintf("From: %s", $this->sender);
    for ($i = 1; $i < count($this->recipients); $i++) {
      $h[] = sprintf("To: %s", $this->recipients[$i]);
    }

    $m  = "This is a multi-part message in MIME format.\n";
    $m .= "\n";
    $m .= sprintf("--%s\n", $boundary);
    $m .= "Content-Type: text/plain; charset=iso-8859-1\n";
    $m .= "\n";
    $m .= sprintf("%s\n", $this->intro);
    $m .= "\n";

    foreach ($_POST as $n => $v) {
      $m .= sprintf("%s: %s\n", $n, $v);
    }

    foreach ($_FILES as $n => $v) {
      if (@$fd = fopen($v["tmp_name"], "rb")) {
        $m .= sprintf("\n--%s\n", $boundary);
        $m .= sprintf("Content-Type: application/octet-stream; name=\"%s\"\n", $v["name"]);
        $m .= "Content-Transfer-Encoding: base64\n";
        $m .= sprintf("Content-Description: %s\n", $v["name"]);
        $m .= sprintf("Content-Disposition: attachment; filename=%s\n\n", $n);

        $buf = fread($fd, $v["size"]);
        $m .= chunk_split(base64_encode($buf), 76, "\n");
        fclose($fd);

        unset($buf);
      }
    }

    mail($this->recipients[0],
         $this->subject,
         $m,
         join("\n", $h));


    if ($this->followupURL != null) {
      header(sprintf("Location: %s", $this->followupURL));
      exit(0);
    } else {
      fail("Thank you for submitting the form.", 0);
    }
  }
}

function formmail($mailfrom,
        $mailto,
        $subject = "formmail.php",
        $intro = "Your web form was sent:",
        $required = "",
        $followup = "",
        $error = "")
{
  if ($_SERVER["REQUEST_METHOD"] != "POST") {
    return;
  }

  $f = new FormMailClass();

  $f->setSender($mailfrom);
  $f->addRecipient($mailto);
  $f->setSubject($subject);
  $f->setIntro($intro);
  $f->setRequiredFields(explode(",", $required));
  $f->setFollowupURL($followup);
  $f->setErrorURL($error);
  $f->process();
}

?>
  View user's profile Private Nachricht senden
pixelpapst303

Dabei seit: 06.07.2006
Ort: hamburg
Alter: 50
Geschlecht: Männlich
Verfasst Fr 28.11.2008 10:12
Titel

Antworten mit Zitat Zum Seitenanfang

an dieser stelle...

Code:

foreach ($_POST as $n => $v) {
      $m .= sprintf("%s: %s\n", $n, $v);
    }


...wird dein mailtext in der reihenfolge des post-arrays zusammengesetzt. wenn du das ohne umbau des formulars machen willst, wirst du da wohl händisch eingreifen müssen...

je nachdem, wie vielseitig du den mailer halten willst, musst du a) dir eine dynamische sortierlogik ausdenken, oder b) die mail dort per hand zusammenbauen...

bspw
Code:

$m .= "Name: ".$_POST['name'];
usw.
  View user's profile Private Nachricht senden Website dieses Benutzers besuchen
 
Ähnliche Themen PDF Formular: an PHP-Script
Kleines Java-Script für Acrobat Formular
suche Upload-script und E-Mail formular in einem
Spam-Schutz für Formular - Java-Script muss geändert werden
html formular
formular in html
Neues Thema eröffnen   Neue Antwort erstellen
MGi Foren-Übersicht -> Programmierung


Du kannst keine Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum nicht antworten.
Du kannst an Umfragen in diesem Forum nicht mitmachen.