Ciao a tutti.Ho provato questo script e (per fortuna) sono riuscito a farlo funzionare!!! :P
Ora... il problema è che vorrei aggiungere un controllo di alcuni campi, quali l'email e il numero di telefono cioè che per esempio se inserisci delle lettere nel campo cellulare o non inserisci la chiocciola nel campo email il form ti dia errore.
Come fare?
Posto i codici
Codice PHP:
<?php
include('contact_settings.php');
include('TemplateMailer.class.php');
$temp = new TemplateMailer();
$types = '';
foreach ($reasons as $type => $mail) {
$types .= "<option value=\"$type\">$type</option>\n";
}
$temp->assign('reasons',$types);
$disya = basename($_SERVER['PHP_SELF']);
$disya = str_replace('.php','.tpl.html',$disya);
$temp->assign("template_file",$disya);
$temp->preparemail($template_folder . $disya);
echo $temp->body;
?>
Codice PHP:
<FORM method="POST" action="contact_sent.php" name="contact_frm">
<TABLE border=0>
<TR>
<TD>Tuo nome:
<INPUT type="text" name="name" size=48></TD>
</TR>
<TR>
<TD>Tua E-mail:
<INPUT type="text" name="email" size=48>
<FONT class=RequiredField> *</FONT></TD>
</TR>
<TR>
<TD>Tuo cellulare:
<INPUT type="text" name="phone" size=48></TD>
</TR>
<TR>
<TD>Ci contatti perchè:
<select name='reason'>
{$reasons}
</select> </TD>
</TR>
<TD>In quanti siete:
<input type="text" name="person" size="48" /> </TD>
</TR>
<TR>
<TD>Oggetto del messaggio:
<input type="text" name="subject" size="48" /></TD>
</TR>
<TR>
<TD valign=top>Messaggio: *
<TEXTAREA name="text" cols=40 rows=10></TEXTAREA></TD>
</TR>
<TR>
<TD>
<INPUT type=image src="contact-send.gif" value="Send"></TD>
</TR>
</TABLE>
</FORM>
Codice PHP:
<?php
error_reporting(0);
include('contact_settings.php');
include('TemplateMailer.class.php');
$temp = new TemplateMailer();
function daj($msg) {
global $template_folder,$temp;
$temp->assign('errmsg',$msg);
$temp->preparemail($template_folder . 'contact_error.tpl.html');
die($temp->body);
}
$name = $_POST['name'];
$email = $_POST['email'];
if (trim($email) == "") { daj("You have to enter email adress so we can reply to you!"); }
$phone = $_POST['phone'];
$reason = $_POST['reason'];
$person = $_POST['person'];
$subj = $_POST['subject'];
$description = $_POST['text'];
if (trim($description) == "") { daj("You have to enter message!"); }
$temp->assign('name',$name);
$temp->assign('email',$email);
$temp->assign('phone',$phone);
$temp->assign('reason',$reason);
$temp->assign('person',$person);
$temp->assign('message',$description);
$temp->preparemail($template_folder . 'contact_mail.tpl.html');
$adresa = $reasons[$reason];
$sent = $temp->send($email,$adresa,$email_subject.' '.$subj,'');
if ($sent) {
$disya = basename($_SERVER['PHP_SELF']);
$disya = str_replace('.php','.tpl.html',$disya);
$temp->assign("template_file",$disya);
$temp->preparemail($template_folder . $disya);
echo $temp->body;
}
else { daj("There was an error with sending e-mail message. Please try again later!"); }
?>
Codice PHP:
<?php
//define project types and emails of persons in charge
$reasons = array(
"Ti chiedo una lista"=>"andrea.d@enjoytoz.it",
"Ti chiedo un tavolo"=>"andrea.d@enjoytoz.it",
"Ti chiedo info"=>"andrea.d@enjoytoz.it",
"Voglio dare un suggerimento per questo sito"=>"andrea.d@enjoytoz.it,andrea.dalledonne@yahoo.it",
"Non avete risposto alla mia precedente domanda"=>"andrea.d@enjoytoz.it",
"Non definito nella lista"=>"andrea.d@enjoytoz.it"
);
//specify folder with templates, with backslash at the end
$template_folder = './templates/';
//subject of email?
$email_subject = 'xyz';
?>