Avatar billede sotec Nybegynder
12. februar 2004 - 13:31 Der er 10 kommentarer og
1 løsning

Funktion - fortløbende nummer i mail subject?

Jeg har en simpel supportformular hvor alle spørgsmål blot sendes til mig via mail().

Hvordan kan jeg på enkel vis udbygge dette med en lille funktion sådan at subject får teksten "Supporthenvendelse nr. 0010 - 12.02.2004" eller lign.?

Det skal være super simpelt, og jeg er ikke så skrap til PHP - sådan nærmest en cut-n-paste programmør, så et lille kode eksempel vil være perfekt.

Fortløbende kan vel ikke blive uden DB ?
Skriv venligst en create table for mig også hvis det ikke kan laves med en tekstfil.

Her er min kode:


<?
if (
($_POST["domain"]) &&
($_POST["name"]) &&
($_POST["mail"]) &&
($_POST["phone"]) &&
($_POST["problem"])
)
{

$to = "POSTMODTAGER";
$afsender = $_POST["mail"];
$subject ="Supporthenvendelse";

// HTML mail

$mailindhold = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="500" border="0" cellpadding="3" cellspacing="0">
<tr><td colspan="2"><b>Supporthenvendelse</b></td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td>Domæne:</td><td>'.$_POST["domain"].'</td></tr>
<tr><td>Kontaktperson:</td><td>'.$_POST["name"].'</td></tr>
<tr><td>E-mail:</td><td>'.$_POST["mail"].'</td></tr>
<tr><td>Telefon:</td><td>'.$_POST["phone"].' </td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td valign="top">Problem:</td><td>'.$_POST["problem"].' </td></tr>
</table>
<br><br>
</body>
</html>
';

// HTML mail

$header = "Content-type: text/html; charset=iso-8859-1";
$header .= "\nFrom: " . $afsender;

mail($to, $subject, $mailindhold, $header);


echo "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n";
echo "<head>\n";
echo "<meta http-equiv='content-type' content='text/html;charset=iso-8859-1'>\n";
echo "<title>Supportformular</title>\n";
echo "<link href='phpcss.css' rel='stylesheet' type='text/css' media='all'>\n";
echo "</head>\n";
echo "<body>\n";
echo "<br><br>\n";
echo "<div align='center'><p>Din supporthenvendelse er modtaget!</p><p>Tillad venligst op til 8 timers sagsbehandling.</p><p><a href='index.php'>Retur til forsiden</a></p>\n";
echo "</body>\n";
echo "</html>\n";



}
else {
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Supportformular</title>
<link href="phpcss.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<br><br>
<table  border="0" cellspacing="0" cellpadding="10" align="center">
<form action="<? echo "$PHP_SELF" ?>" method="POST">
<tr>
<td><p>Dom&aelig;ne navn:<? if (!$_POST["domain"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="domain" value="<? echo $_POST["domain"]; ?>"></td>
</tr>
<tr>
<td><p>Kontaktperson:<? if (!$_POST["name"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="name" value="<? echo $_POST["name"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt mail:<? if (!$_POST["mail"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="mail" value="<? echo $_POST["mail"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt telefon:<? if (!$_POST["phone"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="phone" value="<? echo $_POST["phone"]; ?>"></td>
</tr>
<tr><td colspan="2" align="right">Opgiv venligst et direkte nr. hvis muligt!</td>
</tr>
<tr>
<td colspan="2" align="left"><p>Problem beskrivelse:<? if (!$_POST["problem"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?><br>
<textarea name="problem" style="width: 320px; height: 100px"><? echo $_POST["problem"]; ?></textarea></p></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" class="knap" name="submit" value="Send sp&oslash;rgsm&aring;l"></td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
Avatar billede apache999 Nybegynder
12. februar 2004 - 13:40 #1
Hvis du tør kaste dig ud i en MySQL-ting, er det jo let nok, men så må du lige råbe op. Ellers kan du lave noget med en fil på serveren, der indeholder det tal, du nu er nået til, og som funktionen så lige læser fra og opdaterer, inden den mailer.

Datoen kan du bruge gmdate() til at skrive ind i subjectet.

$subject = "Supporthenvendelse ".gmdate("d.m.Y");
Avatar billede sotec Nybegynder
12. februar 2004 - 13:44 #2
Jeg kan sagtens betjene phpMyAdmin, men kan ikke hitte ud af at lave SQL kommandoen til at skabe tabellen.

Vil meget gerne have modificeret min kode direkte :-)
Avatar billede apache999 Nybegynder
12. februar 2004 - 13:47 #3
OK. Bikser noget sammen. Der går lige 5 minutter.
Avatar billede apache999 Nybegynder
12. februar 2004 - 14:00 #4
Først skal du skrive følgende SQL-query i dit query-vindue i PHPMyAdmin:

CREATE TABLE support (id INT);

Den modificerede kode er neden for. Jeg har markeret, hvor mine ændringer er, og du skal selvfølgelig selv sætte host, login, password og database ind.


<?
if (
($_POST["domain"]) &&
($_POST["name"]) &&
($_POST["mail"]) &&
($_POST["phone"]) &&
($_POST["problem"])
)
{

$to = "POSTMODTAGER";
$afsender = $_POST["mail"];

// MINE ÆNDRINGER STARTER HER

//Henter sidste ID fra databasen
$strSQL = "SELECT id FROM support";

$link = mysql_connect("DIN HOST", "DIT LOGIN", "DIT PASSWORD");

if (!$link)    die (mysql_error());
   
if (!mysql_select_db ("DIN DATABASE" , $link))    die (mysql_error());
   
$output = mysql_query ($strSQL,$link);
               
if (!$output) die (mysql_error());
       
mysql_close($link);
           
while($data = mysql_fetch_array($output)) $id = $data['id'];

// Opdaterer databasen
$strSQL = "UPDATE support SET id = id+1";

if (!$link)    die (mysql_error());
   
if (!mysql_select_db ("DIN DATABASE" , $link))    die (mysql_error());
   
$output = mysql_query ($strSQL,$link);
               
if (!$output) die (mysql_error());
       
mysql_close($link);

$subject = "Supporthenvendelse nr. $id ".gmdate("d.m.Y");

// MINE ÆNDRINGER SLUTTER HER

// HTML mail

$mailindhold = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="500" border="0" cellpadding="3" cellspacing="0">
<tr><td colspan="2"><b>Supporthenvendelse</b></td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td>Domæne:</td><td>'.$_POST["domain"].'</td></tr>
<tr><td>Kontaktperson:</td><td>'.$_POST["name"].'</td></tr>
<tr><td>E-mail:</td><td>'.$_POST["mail"].'</td></tr>
<tr><td>Telefon:</td><td>'.$_POST["phone"].' </td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td valign="top">Problem:</td><td>'.$_POST["problem"].' </td></tr>
</table>
<br><br>
</body>
</html>
';

// HTML mail

$header = "Content-type: text/html; charset=iso-8859-1";
$header .= "\nFrom: " . $afsender;

mail($to, $subject, $mailindhold, $header);


echo "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n";
echo "<head>\n";
echo "<meta http-equiv='content-type' content='text/html;charset=iso-8859-1'>\n";
echo "<title>Supportformular</title>\n";
echo "<link href='phpcss.css' rel='stylesheet' type='text/css' media='all'>\n";
echo "</head>\n";
echo "<body>\n";
echo "<br><br>\n";
echo "<div align='center'><p>Din supporthenvendelse er modtaget!</p><p>Tillad venligst op til 8 timers sagsbehandling.</p><p><a href='index.php'>Retur til forsiden</a></p>\n";
echo "</body>\n";
echo "</html>\n";



}
else {
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Supportformular</title>
<link href="phpcss.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<br><br>
<table  border="0" cellspacing="0" cellpadding="10" align="center">
<form action="<? echo "$PHP_SELF" ?>" method="POST">
<tr>
<td><p>Dom&aelig;ne navn:<? if (!$_POST["domain"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="domain" value="<? echo $_POST["domain"]; ?>"></td>
</tr>
<tr>
<td><p>Kontaktperson:<? if (!$_POST["name"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="name" value="<? echo $_POST["name"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt mail:<? if (!$_POST["mail"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="mail" value="<? echo $_POST["mail"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt telefon:<? if (!$_POST["phone"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="phone" value="<? echo $_POST["phone"]; ?>"></td>
</tr>
<tr><td colspan="2" align="right">Opgiv venligst et direkte nr. hvis muligt!</td>
</tr>
<tr>
<td colspan="2" align="left"><p>Problem beskrivelse:<? if (!$_POST["problem"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?><br>
<textarea name="problem" style="width: 320px; height: 100px"><? echo $_POST["problem"]; ?></textarea></p></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" class="knap" name="submit" value="Send sp&oslash;rgsm&aring;l"></td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
Avatar billede apache999 Nybegynder
12. februar 2004 - 14:01 #5
Ææææh.

Jeg har ikke testet det, så det er kodet på rutinen. Du må lige gø af mig, hvis det ikke virker.
Avatar billede sotec Nybegynder
12. februar 2004 - 14:10 #6
Jeg får en:
Warning: 1 is not a valid MySQL-Link resource in support.php on line 38
Avatar billede apache999 Nybegynder
12. februar 2004 - 14:19 #7
Whoops.

Ny version:

<?
if (
($_POST["domain"]) &&
($_POST["name"]) &&
($_POST["mail"]) &&
($_POST["phone"]) &&
($_POST["problem"])
)
{

$to = "POSTMODTAGER";
$afsender = $_POST["mail"];

// MINE ÆNDRINGER STARTER HER

//Henter sidste ID fra databasen
$strSQL = "SELECT id FROM support";

$link = mysql_connect("DIN HOST", "DIT LOGIN", "DIT PASSWORD");

if (!$link)    die (mysql_error());
   
if (!mysql_select_db ("DIN DATABASE" , $link))    die (mysql_error());
   
$output = mysql_query ($strSQL,$link);
               
if (!$output) die (mysql_error());
       
mysql_close($link);
           
while($data = mysql_fetch_array($output)) $id = $data['id'];

// Opdaterer databasen
$strSQL = "UPDATE support SET id = id+1";

if (!$link)    die (mysql_error());
   
if (!mysql_select_db ("DIN DATABASE" , $link))    die (mysql_error());
   
$output = mysql_query ($strSQL,$link);
               
if (!$output) die (mysql_error());
       
mysql_close($link);

$subject = "Supporthenvendelse nr. $id ".gmdate("d.m.Y");

// MINE ÆNDRINGER SLUTTER HER

// HTML mail

$mailindhold = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="500" border="0" cellpadding="3" cellspacing="0">
<tr><td colspan="2"><b>Supporthenvendelse</b></td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td>Domæne:</td><td>'.$_POST["domain"].'</td></tr>
<tr><td>Kontaktperson:</td><td>'.$_POST["name"].'</td></tr>
<tr><td>E-mail:</td><td>'.$_POST["mail"].'</td></tr>
<tr><td>Telefon:</td><td>'.$_POST["phone"].' </td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td valign="top">Problem:</td><td>'.$_POST["problem"].' </td></tr>
</table>
<br><br>
</body>
</html>
';

// HTML mail

$header = "Content-type: text/html; charset=iso-8859-1";
$header .= "\nFrom: " . $afsender;

mail($to, $subject, $mailindhold, $header);


echo "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n";
echo "<head>\n";
echo "<meta http-equiv='content-type' content='text/html;charset=iso-8859-1'>\n";
echo "<title>Supportformular</title>\n";
echo "<link href='phpcss.css' rel='stylesheet' type='text/css' media='all'>\n";
echo "</head>\n";
echo "<body>\n";
echo "<br><br>\n";
echo "<div align='center'><p>Din supporthenvendelse er modtaget!</p><p>Tillad venligst op til 8 timers sagsbehandling.</p><p><a href='index.php'>Retur til forsiden</a></p>\n";
echo "</body>\n";
echo "</html>\n";



}
else {
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Supportformular</title>
<link href="phpcss.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<br><br>
<table  border="0" cellspacing="0" cellpadding="10" align="center">
<form action="<? echo "$PHP_SELF" ?>" method="POST">
<tr>
<td><p>Dom&aelig;ne navn:<? if (!$_POST["domain"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="domain" value="<? echo $_POST["domain"]; ?>"></td>
</tr>
<tr>
<td><p>Kontaktperson:<? if (!$_POST["name"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="name" value="<? echo $_POST["name"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt mail:<? if (!$_POST["mail"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="mail" value="<? echo $_POST["mail"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt telefon:<? if (!$_POST["phone"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="phone" value="<? echo $_POST["phone"]; ?>"></td>
</tr>
<tr><td colspan="2" align="right">Opgiv venligst et direkte nr. hvis muligt!</td>
</tr>
<tr>
<td colspan="2" align="left"><p>Problem beskrivelse:<? if (!$_POST["problem"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?><br>
<textarea name="problem" style="width: 320px; height: 100px"><? echo $_POST["problem"]; ?></textarea></p></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" class="knap" name="submit" value="Send sp&oslash;rgsm&aring;l"></td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
Avatar billede apache999 Nybegynder
12. februar 2004 - 14:20 #8
NOOO. Glemte lige at tilføje rettelsen. Ny Ny Version:

<?
if (
($_POST["domain"]) &&
($_POST["name"]) &&
($_POST["mail"]) &&
($_POST["phone"]) &&
($_POST["problem"])
)
{

$to = "POSTMODTAGER";
$afsender = $_POST["mail"];

// MINE ÆNDRINGER STARTER HER

//Henter sidste ID fra databasen
$strSQL = "SELECT id FROM support";

$link = mysql_connect("DIN HOST", "DIT LOGIN", "DIT PASSWORD");

if (!$link)    die (mysql_error());
   
if (!mysql_select_db ("DIN DATABASE" , $link))    die (mysql_error());
   
$output = mysql_query ($strSQL,$link);
               
if (!$output) die (mysql_error());
       
while($data = mysql_fetch_array($output)) $id = $data['id'];

// Opdaterer databasen
$strSQL = "UPDATE support SET id = id+1";

if (!$link)    die (mysql_error());
   
if (!mysql_select_db ("DIN DATABASE" , $link))    die (mysql_error());
   
$output = mysql_query ($strSQL,$link);
               
if (!$output) die (mysql_error());
       
mysql_close($link);

$subject = "Supporthenvendelse nr. $id ".gmdate("d.m.Y");

// MINE ÆNDRINGER SLUTTER HER

// HTML mail

$mailindhold = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="500" border="0" cellpadding="3" cellspacing="0">
<tr><td colspan="2"><b>Supporthenvendelse</b></td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td>Domæne:</td><td>'.$_POST["domain"].'</td></tr>
<tr><td>Kontaktperson:</td><td>'.$_POST["name"].'</td></tr>
<tr><td>E-mail:</td><td>'.$_POST["mail"].'</td></tr>
<tr><td>Telefon:</td><td>'.$_POST["phone"].' </td></tr>
<tr><td colspan="2"><hr size="1" color="#000000" noshade></td></tr>
<tr><td valign="top">Problem:</td><td>'.$_POST["problem"].' </td></tr>
</table>
<br><br>
</body>
</html>
';

// HTML mail

$header = "Content-type: text/html; charset=iso-8859-1";
$header .= "\nFrom: " . $afsender;

mail($to, $subject, $mailindhold, $header);


echo "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n";
echo "<head>\n";
echo "<meta http-equiv='content-type' content='text/html;charset=iso-8859-1'>\n";
echo "<title>Supportformular</title>\n";
echo "<link href='phpcss.css' rel='stylesheet' type='text/css' media='all'>\n";
echo "</head>\n";
echo "<body>\n";
echo "<br><br>\n";
echo "<div align='center'><p>Din supporthenvendelse er modtaget!</p><p>Tillad venligst op til 8 timers sagsbehandling.</p><p><a href='index.php'>Retur til forsiden</a></p>\n";
echo "</body>\n";
echo "</html>\n";



}
else {
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Supportformular</title>
<link href="phpcss.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<br><br>
<table  border="0" cellspacing="0" cellpadding="10" align="center">
<form action="<? echo "$PHP_SELF" ?>" method="POST">
<tr>
<td><p>Dom&aelig;ne navn:<? if (!$_POST["domain"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="domain" value="<? echo $_POST["domain"]; ?>"></td>
</tr>
<tr>
<td><p>Kontaktperson:<? if (!$_POST["name"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="name" value="<? echo $_POST["name"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt mail:<? if (!$_POST["mail"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="mail" value="<? echo $_POST["mail"]; ?>"></td>
</tr>
<tr>
<td><p>Kontakt telefon:<? if (!$_POST["phone"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?></p></td>
<td><input type="text" style="width: 210px" name="phone" value="<? echo $_POST["phone"]; ?>"></td>
</tr>
<tr><td colspan="2" align="right">Opgiv venligst et direkte nr. hvis muligt!</td>
</tr>
<tr>
<td colspan="2" align="left"><p>Problem beskrivelse:<? if (!$_POST["problem"]) { echo "<font color=\"#ff0000\">*</font>" ; } ?><br>
<textarea name="problem" style="width: 320px; height: 100px"><? echo $_POST["problem"]; ?></textarea></p></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" class="knap" name="submit" value="Send sp&oslash;rgsm&aring;l"></td>
</tr>
</form>
</table>
</body>
</html>
<?
}
?>
Avatar billede sotec Nybegynder
12. februar 2004 - 14:27 #9
Det virker, men der bliver ikke indsat noget i DB og subject har ikke nr. kun dato.
Skal jeg indsætte et tal fra starten med phpMyAdmin??
Avatar billede sotec Nybegynder
12. februar 2004 - 14:29 #10
Aha, yes det virker hvis jeg indsætter et tal!
Avatar billede sotec Nybegynder
12. februar 2004 - 14:36 #11
Tak for hjælpen.
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