Simpel e-mail funktion. (Flere variabler i samme body)
Hejsa.Jeg har fået bikset en e-mail funktion sammen, som tilmed virker:) Nu skal jeg bare ændre lidt på den, men jeg er lidt i tvivl om hvordan og hvorledes. Koden ser sådan ud:
<?php
//simple_mailer.php
function mailer_header()
{
?>
<HTML>
<HEAD><TITLE>E-mailer</TITLE></HEAD>
<BODY>
<?php
}
function mailer_footer()
{
?>
</BODY>
</HTML>
<?php
}
function error_massage($msg)
{
mailer_header();
echo "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
mailer_footer();
exit;
}
function user_message($msg)
{
mailer_header();
echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
mailer_footer();
exit;
}
function mail_form()
{
global $PHP_SELF;
?>
<FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA"
ACTION="<?php echo $PHP_SELF; ?>">
<INPUT TYPE="hidden" NAME="action" VALUE="send_mail">
<DIV ALIGN="CENTER ">
<TABLE CELLSPACING"2" CELLPADDING="5" WIDTH"90%" BORDER"1">
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Sendes til</TH>
<TD WIDTH="70%"><INPUT NAME="mail_to" VALUE="insertcoins@team-rc.dk" SIZE="30"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Fra</TH>
<TD WIDTH="70%"><INPUT NAME="mail_from" VALUE="Dit navn" SIZE="30"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Svar til</TH>
<TD WIDTH="70%"><INPUT NAME="mail_reply_to" VALUE="din@email.com" SIZE="30"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Emne</TH>
<TD WIDTH="70%"><INPUT NAME="mail_subject" VALUE="Tildmelding til dogfight" SIZE="40"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Oplysninger</TH>
<TD WIDTH="70%"><TEXTAREA NAME="mail_body" ROWS="16"
COLS="70"></TEXTAREA></TD>
</TR>
<TR>
<TH WIDTH="100%" COLSPAN="2" ALIGN="CENTER">
<INPUT TYPE="SUBMIT" VALUE="Send" NAME="SUBMIT">
<INPUT TYPE="RESET" VALUE="Reset" NAME="Reset">
</TH>
</TR>
</TABLE>
</DIV>
</FORM>
<?php
}
function send_mail()
{
global $mail_to, $mail_from, $mail_reply_to;
global $mail_body, $mail_subject;
$mail_parts["mail_to"] = $mail_to;
$mail_parts["mail_from"] = $mail_from;
$mail_parts["mail_reply_to"] = $mail_reply_to;
$mail_parts["mail_subject"] = trim($mail_subject);
$mail_parts["mail_body"] = $mail_body;
if(my_mail($mail_parts))
user_message("Successfully sent an e-mail titled '$mail_subject'.");
else error_message("An unknown error ocurred while attempting to send an e-mail titled '$mail_subject'.");
}
function my_mail($mail_parts)
{
$mail_to = $mail_parts["mail_to"];
$mail_from = $mail_parts["mail_from"];
$mail_reply_to = $mail_parts["mail_reply_to"];
$mail_subject = $mail_parts["mail_subject"];
$mail_body = $mail_parts["mail_body"];
if(empty($mail_to)) error_message("Empty to field!");
if(empty($mail_subject)) error_message("Empty subject!");
if(empty($mail_body)) error_message("Empty body! ");
$mail_to = str_replace(";", ",", $mail_to);
$mail_header = '';
if(!empty($mail_from)) $mail_headers .= "From: $mail_from\n";
if(!empty($mail_reply_to)) $mail_headers .= "Reply-to: $mail_reply_to\n";
$mail_subject = stripslashes($mail_subject);
$mail_body = stripslashes($mail_body);
return mail($mail_to,$mail_subject,$mail_body,$mail_headers);
}
switch ($action)
{
case "send_mail":
mailer_header();
send_mail();
mailer_footer();
break;
case "mail_form":
mailer_header();
mail_form();
mailer_footer();
break;
default:
mailer_header();
mail_form();
mailer_footer();
break;
}
?>
Jeg skal have lavet følgende:
$mail_to skal være en fast e-mail, som brugeren ikke kan ændre på (insertcoins@team-rc.dk), og det skal subject også (Tilmelding til dogfight)
Html formen skal ændres til følgende:
<DIV ALIGN="CENTER ">
<TABLE CELLSPACING"2" CELLPADDING="5" WIDTH"90%" BORDER"1">
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Holdnavn</TH>
<TD WIDTH="70%"><INPUT NAME="mail_holdnavn" SIZE="40"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Spiller 1</TH>
<TD WIDTH="70%"><INPUT NAME="mail_spiller1" SIZE="40"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">Spiller 2</TH>
<TD WIDTH="70%"><INPUT NAME="mail_spiller2" SIZE="40"></TD>
</TR>
<TR>
<TH ALIGN="CENTER" "WIDTH="30%">E-mail</TH>
<TD WIDTH="70%"><INPUT NAME="mail_reply_to" SIZE="30"></TD>
</TR>
Det jeg vil have den til, er at når jeg modtager e-mailen, skal $mail_holdnavn, $mail_spiller1 og $mail_spiller2 blive vist i min body e-mail. Imens $mail_reply_to bliver smidt ind, så jeg kan trykke besvar.
Håber der er nogen der kan hjælpe mig og hvis der er noget i ikke forstår må i endelig sige til.
Mvh Sune