script asp invio mail con dati di un form

franklin_92

Nuovo Utente
19 Dic 2006
12
0
0
salve a tutti, utilizzo attualmente un servizio di redirect gratuito (AbcZone )per inviare il contenuto di un form(Grand Hotel Sant'Angelo - Prenotazioni ) a un indirizzo email. Vorrei creare uno script asp per mandare l'email in modo da
1.non utilizzare un servizio esterno
2.possibilità di modificare l'oggetto 3.
decidere la struttura dell'email ottenendo il seguente risultato:

Oggetto: prenotazione (data odierna)
Dati Anagrafici
Nome:
Cognome:
Città:
Indirizzo:
Nazione:
Telefono:
Fax:
E-Mail:
Info:

Prenotazione
Data Arrivo:
Data Partenza:
n° camere singole
n° camere doppie
tipo camere singole
tipo camere doppie
tipo pernottamento:

aspetto vostre risposte
 
Io utilizzo uno script "sendmail.asp" che funziona abbastanza bene. Nel form indico
"action="sendmail.asp" method="POST" enctype="x-www-form-encoded"
di seguito lo script di controllo del form e lo script "sendmail". Guarda se può fare al tuo caso.


<!-- controllo campi form -->
<script language="JavaScript">
<!--
function validate_form() {
validity = true; // assume valid
if (!check_empty(document.form.Nome.value))
{ validity = false; alert('Inserire il Nome'); }
if (!check_empty(document.form.Cognome.value))
{ validity = false; alert('Inserire il Cognome'); }
if (!check_empty(document.form.Indirizzo.value))
{ validity = false; alert('Inserire Indirizzo'); }
if (!check_empty(document.form.Citta.value))
{ validity = false; alert('Inserire la Città'); }
if (!check_empty(document.form.Provincia.value))
{ validity = false; alert('Inserire la Provincia'); }
if (!check_empty(document.form.email.value))
{ validity = false; alert('Inserire indirizzo E-Mail'); }
if (!check_empty(document.form.email.value) || !check_email(document.form.email.value))
{ validity = false; alert('Avete inserito una E-Mail errata'); }
if (validity)
alert ("Il form è corretto.");
return validity;
}

function check_empty(text) {
return (text.length > 0); // returns false if empty
}

function check_email(Email) {
if ((Email == "")
|| (Email.indexOf ('@') == -1)
|| (Email.indexOf ('.') == -1))
return false;
return true;
}
// -->
</script>
<!-- fine controllo campi form -->


-------------------------------------------------

sendmail.asp


<%

indirizzo_destinazione = "info@...............it"
indirizzo_destinazioneCC = "............@libero.it"
oggetto = "Modulo inviato dal Sito ................"
pagina_successiva = "grazie.htm"


'--------------------------------------------------------------------------------

email = Request.form("email")

if email <> "" then
MAIL( FormData() )

if pagina_successiva <> "" then
response.redirect(pagina_successiva)
else
response.redirect("index.htm")
end if
else
response.write("Manca l'indirizzo del mittente (campo ""email"") - Spedizione fallita")
response.end
end if


'--------------------------------------------------------------------------------

provenienza = Request.ServerVariables("HTTP_REFERER")

if provenienza <> "http://www...................it/form.html" and provenienza <> "http://www...............it/commenti.html" then
response.redirect("http://www.................it/errore.html")
end if

'--------------------------------------------------------------------------------



'DEBUG FORM

'Response.Write FormData()


Function FormData()
Dim llngMaxFieldIndex
Dim llngFieldIndex
Dim llngMaxValueIndex
Dim llngValueIndex
Dim lstrDebug

llngMaxFieldIndex = Request.Form.Count

' Let user know if Form do not exist
If llngMaxFieldIndex = 0 Then
FormData = "Il Form &egrave; vuoto!"
Exit Function
End If

' Begin building a list of all Form
lstrDebug = "<table width=""400""><font face=""verdana"" size=""12"">"

' Loop through each Form
For llngFieldIndex = 1 To llngMaxFieldIndex
lstrDebug = lstrDebug & "<tr><td>" & Server.HTMLEncode(Request.Form.Key(llngFieldIndex))

' Count the values
llngMaxValueIndex = Request.Form(llngFieldIndex).Count

' If the Field doesn't have multiple values ...
If llngMaxValueIndex = 1 Then
lstrDebug = lstrDebug & " </td><td> "
lstrDebug = lstrDebug & Server.HTMLEncode(Request.Form.Item(llngFieldIndex))
' Else loop through each value
Else
lstrDebug = lstrDebug & " </td><td>"
For llngValueIndex = 1 to llngMaxValueIndex
'lstrDebug = lstrDebug & "<LI>"
lstrDebug = lstrDebug & Server.HTMLEncode(Request.Form(llngFieldIndex)(llngValueIndex))
lstrDebug = lstrDebug & "<br>"
Next
'lstrDebug = lstrDebug & "</OL>"
End If
lstrDebug = lstrDebug & "</td><tr>"
Next
lstrDebug = lstrDebug & "</table>"
' Return the data
FormData = lstrDebug

End Function

Function MAIL(body)

'---------------------------------------------------------------
'Oggetto ASPMail

Set Mailer = Server.CreateObject("CDONTS.newmail")
Mailer.From = email
Mailer.to = indirizzo_destinazione
if indirizzo_destinazioneCC <> "" then
Mailer.CC = indirizzo_destinazioneCC
end if
Mailer.Subject = oggetto
Mailer.BodyFormat = 0
Mailer.MailFormat = 0
Mailer.Body = body
Mailer.Send
Set Mailer = Nothing

End Function


%>
 

Discussioni simili