Dabei seit: 01.06.2006 Ort: Upper-Eastside Helvetia Alter: 36 Geschlecht:
Verfasst Do 27.11.2008 12:14 Titel
html-formular via php-script
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?
Dabei seit: 01.06.2006 Ort: Upper-Eastside Helvetia Alter: 36 Geschlecht:
Verfasst Do 27.11.2008 12:35 Titel
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 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));
}
}
}
...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...
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.