Zum Inhalt springen

Kontaktformular Email-Betreff

Erstellt am 23. Februar 2007 · Noch keine Antworten

Tags: PHP, E-Mail-Versand, Frage

vihringer ·

Hallo,

ich habe derzeit ein Problem bezüglich eines Kontaktformulars. Unsere Website mit Typo3 wurde damals extern eingerichtet und dabei wurden auch verschiedene Extensions eingefügt.

Dabei ist auch ein Kontaktformular, in denen Websitebesucher ankreuzen können, ob sie Infomaterial erhalten möchten und sie müssen ihren Namen, Firma usw. angeben.

Wenn jemand ein solches Kontaktformular ausfüllt, erhalten wir eine Email, welche die ganzen Daten des Formulars ausgefüllt enthält.

Den Betreff der Email kann man in der Extension verändern, allerdings möchte ich, dass die Eingabefelder "Company" und "City" ausgelesen werden und schon direkt im Betreff angezeigt werden und nicht nur in der Email. Grund dafür ist, dass das Sekretariat gleich weiss, wo sie die Email ablegen soll (nach PLZ geordnet), ohne die Mail durchlesen zu müssen.

Anbei der Quelltext. Wichtig dürfte ja eigentlich nur diese Stelle sein (Zeile 52):

$this->compileMail();
mail($this->contactEmailAddress, "Kontakt: ", $this->message, $this->headers);

Quelltext:

<?php
require_once(PATH_tslib."class.tslib_pibase.php");

class tx_datroncontact_pi1 extends tslib_pibase {
	var $prefixId = "tx_datroncontact_pi1";		// Same as class name
	var $scriptRelPath = "pi1/class.tx_datroncontact_pi1.php";	// Path to this script relative to the extension dir.
	var $extKey = "datron_contact";	// The extension key.

	/**
	 * Displays a contact form, inserts data into the DB
	 */
	function main($content,$conf)	{
		$this->conf=$conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->inputErrors = "";
		$this->inputErrors = $this->checkInput();

		$this->recordStoragePage = $this->conf["recordStoragePage"];
		$this->forwardPage = $this->conf["forwardPage"];
		$this->errorStyleCSS = $this->conf["errorStyleCSS"];
		$this->contactEmailAddress = $this->conf["contactEmailAddress"];
		$this->senderEmailAddress = $this->conf["senderEmailAddress"];

		if(isset($this->piVars['submit_button']) && $this->inputErrors == 0) {

		   $query = 'INSERT INTO tx_datroncontact_content (name, company, division, street, city, telno, fax, email, furtherinfo, cnc, dispense, position, mini, full, call, date, time, pid)
		   VALUES ("'.addslashes($this->piVars['DATA']['name']).'",
		   "'.addslashes($this->piVars['DATA']['company']).'",
		   "'.addslashes($this->piVars['DATA']['division']).'",
		   "'.addslashes($this->piVars['DATA']['street']).'",
		   "'.addslashes($this->piVars['DATA']['city']).'",
		   "'.addslashes($this->piVars['DATA']['telno']).'",
		   "'.addslashes($this->piVars['DATA']['fax']).'",
		   "'.addslashes($this->piVars['DATA']['email']).'",
		   "'.addslashes($this->piVars['DATA']['furtherinfo']).'",
		   "'.addslashes($this->piVars['DATA']['cnc']).'",
		   "'.addslashes($this->piVars['DATA']['dispense']).'",
           "'.addslashes($this->piVars['DATA']['position']).'",
           "'.addslashes($this->piVars['DATA']['mini']).'",
           "'.addslashes($this->piVars['DATA']['full']).'",
           "'.addslashes($this->piVars['DATA']['call']).'",
           "'.addslashes($this->piVars['DATA']['date']).'",
           "'.addslashes($this->piVars['DATA']['time']).'",

		   "'.$this->recordStoragePage.'")';

		   $res = mysql(TYPO3_db, $query);
	/*	   echo mysql_error(); */

		   $this->compileMail();
		   mail($this->contactEmailAddress, "Kontakt: ", $this->message, $this->headers);

		   header ('Location: '.t3lib_div::locationHeaderURL('index.php?id='.$this->forwardPage)); 

		}else{

if($this->piVars["DATA"]["furtherinfo"] == "1")
	$furtherinfo = 'checked="checked"';
if($this->piVars["DATA"]["cnc"] == "1")
	$cnc = 'checked="checked"';
if($this->piVars["DATA"]["dispense"] == "1")
	$dispense = 'checked="checked"';
if($this->piVars["DATA"]["position"] == "1")
	$position = 'checked="checked"';
if($this->piVars["DATA"]["mini"] == "1")
	$mini = 'checked="checked"';
if($this->piVars["DATA"]["full"] == "1")
	$full = 'checked="checked"';
if($this->piVars["DATA"]["call"] == "1")
        $call = 'checked="checked"';

		   $content='
		     <form action="'.$this->pi_getPageLink($GLOBALS["TSFE"]->id).'" method="POST">

			<input type="hidden" name="no_cache" value="1">
<table class="bodytext">
<tr><td>&nbsp;</td></tr>
<tr><td>'.$this->pi_getLL("name").':*</td>
<td><input name="'.$this->prefixId.'[DATA][name]" value="'.htmlspecialchars($this->piVars["DATA"]["name"]).'" type="text" size="30" maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; background:#E5EFF4; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("company").':*</td>
<td><input name="'.$this->prefixId.'[DATA][company]" value="'.htmlspecialchars($this->piVars["DATA"]["company"]).'" type="text" size="30" maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; background:#E5EFF4; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("division").':</td>
<td><input name="'.$this->prefixId.'[DATA][division]" value="'.htmlspecialchars($this->piVars["DATA"]["division"]).'" type="text" size="30" maxlength="70"style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("street").':*</td>
<td><input name="'.$this->prefixId.'[DATA][street]" value="'.htmlspecialchars($this->piVars["DATA"]["street"]).'" type="text" size="30"
maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; background:#E5EFF4; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("city").':*</td>
<td><input name="'.$this->prefixId.'[DATA][city]" value="'.htmlspecialchars($this->piVars["DATA"]["city"]).'" type="text" size="30"
maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; background:#E5EFF4; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("telno").':*</td>
<td><input name="'.$this->prefixId.'[DATA][telno]" value="'.htmlspecialchars($this->piVars["DATA"]["telno"]).'" type="text" size="30"
maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; background:#E5EFF4; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("fax").':</td>
<td><input name="'.$this->prefixId.'[DATA][fax]" value="'.htmlspecialchars($this->piVars["DATA"]["fax"]).'" type="text" size="30"
maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>'.$this->pi_getLL("email").':*</td>
<td><input name="'.$this->prefixId.'[DATA][email]" value="'.htmlspecialchars($this->piVars["DATA"]["email"]).'" type="text" size="30"
maxlength="70" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; background:#E5EFF4; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>

<tr><td>&nbsp;</td><td>'.$this->pi_getLL("required").'</td></tr>
<tr><td>&nbsp;</td><td>'.$this->inputErrors["err_name"].$this->inputErrors["err_company"].$this->inputErrors["err_street"].$this->inputErrors["err_city"].$this->inputErrors["err_telno"].$this->inputErrors["err_email"].'</td></tr>
</table>

<table class="bodytext">
<tr><td><input type="checkbox" name="'.$this->prefixId.'[DATA][furtherinfo]" value="1" '.$furtherinfo.'></td><td><b>'.$this->pi_getLL("furtherinfo").':</b></td></tr>
<tr><td></td><td><input type="checkbox" name="'.$this->prefixId.'[DATA][cnc]" value="1" '.$cnc.'>'.$this->pi_getLL("cnc").'</td></tr>
<tr><td></td><td><input type="checkbox" name="'.$this->prefixId.'[DATA][dispense]" value="1" '.$dispense.'>'.$this->pi_getLL("dispense").'</td></tr>
<tr><td></td><td><input type="checkbox" name="'.$this->prefixId.'[DATA][position]" value="1" '.$position.'>'.$this->pi_getLL("position").'</td></tr>
<tr><td></td><td><input type="checkbox" name="'.$this->prefixId.'[DATA][mini]" value="1" '.$mini.'>'.$this->pi_getLL("mini").'</td></tr>
<tr><td></td><td><input type="checkbox" name="'.$this->prefixId.'[DATA][full]" value="1" '.$full.'>'.$this->pi_getLL("full").'</td></tr>
<tr><td><input type="checkbox" name="'.$this->prefixId.'[DATA][call]" value="1" '.$call.'></td><td><b>'.$this->pi_getLL("call").'</b></td></tr>

<tr><td></td><td>
<table class="bodytext">
<tr><td>
'.$this->pi_getLL("date").':</td>
<td><input name="'.$this->prefixId.'[DATA][date]" value="'.htmlspecialchars($this->piVars["DATA"]["date"]).'" type="text" size="20"
maxlength="30" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>
<tr><td>'.$this->pi_getLL("time").':</td>
<td><input name="'.$this->prefixId.'[DATA][time]" value="'.htmlspecialchars($this->piVars["DATA"]["time"]).'" type="text" size="20"
maxlength="30" style="font-size:12px; font-family:Verdana, Helvetica, Arial, sans-serif; border: #005A96; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px"></td></tr>
</table>
</td></tr>
</table>

<br><input type="submit" name="'.$this->prefixId.'[submit_button]" value="'.htmlspecialchars($this->pi_getLL("submit")).'" style="color:white; background-color:#005A96; font-size:10px; line-height:16px; font-family:Verdana, Helvetica, Arial, sans-serif; width:100px; border:solid 1px #E5EFF4; cursor:hand"  onmouseover="this.style.font=&#39;bold&#39;" onmouseout="this.style.font=&#39;normal&#39;">
<input type="reset" value="'.$this->pi_getLL("reset").'" name="reset"  style="color:white; background-color:#005A96; font-size:10px; line-height:16px; font-family:Verdana, Helvetica, Arial, sans-serif; width:100px; border:solid 1px #E5EFF4; cursor:hand"  onmouseover="this.style.font=&#39;bold&#39;" onmouseout="this.style.font=&#39;normal&#39;"></form>';

		}

//		t3lib_div::debug($this->piVars);
//		t3lib_div::debug($this->inputErrors);
		return $this->pi_wrapInBaseClass($content);
	}

	function checkInput(){
		$this->errorStyleCSS = $this->conf["errorStyleCSS"];

		if ($this->piVars['submit_button'])
		{
		   $errors = array();

		   if($this->piVars["DATA"]["name"] == "")
		   {	$errors["err_name"] = "<span style=\"".$this->errorStyleCSS."\">".$this->pi_getLL("err_name")."</span>";
		   }
		   if($this->piVars["DATA"]["company"] == "")
		   {	$errors["err_company"] = "<span style=\"".$this->errorStyleCSS."\">".$this->pi_getLL("err_company")."</span>";
		   }
                   if($this->piVars["DATA"]["street"] == "")
                   {    $errors["err_street"] = "<span style=\"".$this->errorStyleCSS."\">".$this->pi_getLL("err_street")."</span>";
                   }
                   if($this->piVars["DATA"]["city"] == "")
                   {    $errors["err_city"] = "<span style=\"".$this->errorStyleCSS."\">".$this->pi_getLL("err_city")."</span>";
                   }
                   if($this->piVars["DATA"]["telno"] == "")
                   {    $errors["err_telno"] = "<span style=\"".$this->errorStyleCSS."\">".$this->pi_getLL("err_telno")."</span>";
                   }
		   if(($this->piVars["DATA"]["email"] == "") || ($this->isEmail($this->piVars["DATA"]["email"]) == 0))
		   {	$errors["err_email"] = "<span style=\"".$this->errorStyleCSS."\">".$this->pi_getLL("err_email")."</span>";
		   }

		   if(count($errors) == 0)
		   	$errors = 0;
		}
		return $errors;
	}

	function compileMail(){
if($this->piVars["DATA"]["furtherinfo"] == "1")
        $furtherinfo = 'checked="checked"';
if($this->piVars["DATA"]["cnc"] == "1")
        $cnc = 'checked="checked"';
if($this->piVars["DATA"]["dispense"] == "1")
        $dispense = 'checked="checked"';
if($this->piVars["DATA"]["position"] == "1")
        $position = 'checked="checked"';
if($this->piVars["DATA"]["mini"] == "1")
        $mini = 'checked="checked"';
if($this->piVars["DATA"]["full"] == "1")
        $full = 'checked="checked"';
if($this->piVars["DATA"]["call"] == "1")
        $call = 'checked="checked"';

         $this->message = "
<html>
 <head>
  <title>Bitte um Kontaktaufnahme</title>
 </head>
 <body>
  <p>
   <h1>Kundendaten:<h2>
  </p>
  <table>
   <tr>
    <td>
     <p>Name:</p>
    </td>
    <td>
     <p>".$this->temp_string." ".$this->piVars['DATA']['name']." ".$this->piVars['DATA']['surname']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Firma:</p>
    </td>
    <td>
     <p>".$this->piVars['DATA']['company']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Abteilung:</p>
    </td>
    <td>
     <p>".$this->piVars['DATA']['division']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Stra&szlig;e:</p>
    </td>
    <td>
     <p>".$this->piVars['DATA']['street']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>PLZ/Ort:</p>
    </td>
    <td>
     <p>".$this->piVars['DATA']['city']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Telefonnummer:</p>
    </td>
    <td>
     <p>".$this->piVars['DATA']['telno']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Faxnummer:</p>
    </td>
    <td>
     <p>".$this->piVars['DATA']['fax']."</p>
    </td>
   </tr>
   <tr>
    <td>
     <p>E-Mail Adresse:</p>
    </td>
    <td>
     <p><a href=\"mailto:".$this->piVars['DATA']['email']."\">".$this->piVars['DATA']['email']."</a></p>
   </tr>
   <tr>
    <td>
     <p>Bitte senden Sie mir weitergehende Informationenen &uuml;ber:</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$furtherinfo."></p>
    </td>
   </tr>
   <tr>
    <td>
     <p>DATRON CNC-Bearbeitungssystem</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$cnc."></p>
    </td>
   </tr>
   <tr>
    <td>
     <p>DATRON Dosiersysteme</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$dispense."></p>
    </td>
   </tr>
   <tr>
    <td>
     <p>DATRON Positioniermodule</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$position."></p>
    </td>
   </tr>
   <tr>
    <td>
     <p>DATRON Mini-Tools</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$mini."></p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Das gesamte Produkt- und Dienstleistungsspektrum von DATRON</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$full."></p>
    </td>
   </tr>
   <tr>
    <td>
     <p>Bitte rufen Sie mich am ".$this->piVars['DATA']['date']." um ".$this->piVars['DATA']['time']."an.</p>
    </td>
    <td>
     <p><input type=\"checkbox\" ".$call."></p>
    </td>
   </tr>
  </table>
 </body>
</html>
";
         $this->headers = "From: DATRON Website <".$this->senderEmailAddress.">\n";
         $this->headers .= "X-Sender: <".$this->senderEmailAddress.">\n";
         $this->headers .= "X-Mailer: PHP\n"; //mailer
         $this->headers .= "X-Priority: 3\n"; //1 Urgent, 3 Normal
         $this->headers .= "Return-Path: <".$this->senderEmailAddress.">\n";
         $this->headers .= "Content-Type: text/html; charset=iso-8859-1\n";
	}

	function isEmail($email){
		return ereg("^([a-zA-Z0-9\.\_\-]+)@([a-zA-Z0-9\.\-]+\.[a-zA-Z][A-Za-z]+)$", $email);
	}
}

if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/datron_contact/pi1/class.tx_datroncontact_pi1.php"])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/datron_contact/pi1/class.tx_datroncontact_pi1.php"]);
}

?>