Quello che mi serve è capire il meccanismo per inviare un'email
Forse è meglio se prima posto lo script più complesso che avevo usato all'inizio (lì c'erano anche tutti i parametri), altrimenti ti scomodo per niente. Se noti delle differenze sostanziali mi faresti un favore a postare il tuo, così lo confronto.
Grazie in ogni caso per l'aiuto
Questo è il file principale, che chiamo attraverso la barra degli indirizzi:
Codice PHP:
<html>
<body>
<%
dim oggetto
dim contenuto
oggetto = "Questa è una prova di invio email"
contenuto = "<html><body><h1>Titolo</h1>
"
contenuto = contenuto & "descrizione qualsiasi"
contenuto = contenuto & "</body></html>"
response.write contenuto
myEmail = sendEmail("nome_destinatario", "destinatario@libero.it", "nome_mittente", "mittente@libero.it", oggetto, contenuto, TRUE, "CDOSYS", "mail.smtp_mittente.it")
response.Write "
Email inviata"
%>
</body></html>
Questo invece è il file email.asp che viene richiamato (piuttosto lungo, anche se il codice è commentato):
Codice PHP:
<%
public function sendEmail(toName, toEmail, fromName, fromEmail, emailSubject, emailBody, isHTML, emailComponent, emailServer)
'toName e toEmail : rispettivamente nome ed indirizzo del destinatario
'fromName e fromEmail : rispettivamente nome ed indirizzo del mittente
'emailSubject : oggetto dell'email
'emailBody : contenuto dell'email
'isHTML : se impostato a true invia una email in formato HTML, altrimenti in formato testo
'emailComponent : oggetto email utilizzato
'emailServer : indirizzo SMTP del server d'invio. Necessario per qualsiasi oggetto tranne CDONTS
Dim objMail ' Oggetto email
Dim objMailConfig ' Configurazione oggetto email
Dim blnSent ' Conferma di invio email
Dim strBodySignature ' Firma da aggiungere alle email
blnSent = false 'Assicuriamoci che di default la funzione restituisca false se non vengono inviate email
'*****************************************************************************
' Per i tipi di server
select case emailComponent
' ****** CDONTS *****
case "CDONTS"
' Crea l'oggetto CDONTS
Set objMail = Server.CreateObject("CDONTS.NewMail")
with objMail
' Mittente
.From = fromName & " <" & fromEmail & ">"
' Destinatario
.To = toName & " <" & toEmail & ">"
' Oggetto
.Subject = emailSubject
' Corpo dell'email
if isHTML then
.Body = Replace(strBodyFormat, "$body$", emailBody & strBodySignature)
else
.Body = emailBody & strBodySignature
end if
' Formato corpo : 0 = HTML, 1 = Text
if isHTML then
.BodyFormat = 0
else
.BodyFormat = 1
end If
' Formato email : 0 = MIME, 1 = Text
.MailFormat = 0
' Importanza : 0 = Low, 1 = Normal, 2 = High
.Importance = 1
' Invia l'email
.Send
blnSent = true
end with
Set objMail = Nothing
' ****** CDOSYS *****
case "CDOSYS"
' Crea l'oggetto CDOSYS
Set objMail = Server.CreateObject("CDO.Message")
Set objMailConfig = Server.CreateObject ("CDO.Configuration")
' Proprietà di invio
with objMailConfig
' SMTP mail server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = emailServer
' SMTP port
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' CDO port
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' Timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Fields.Update
end with
' Configurazione CDOSYS
Set objMail.Configuration = objMailConfig
with objMail
' Mittente
.From = fromName & " <" & fromEmail & ">"
' Destinatario
.To = toName & " <" & toEmail & ">"
' Oggetto
.Subject = emailSubject
' Corpo dell'email
if isHTML then
.HTMLBody = Replace(strBodyFormat, "$body$", emailBody & strBodySignature)
.HTMLBody = emailBody & strBodySignature
else
.TextBody = emailBody & strBodySignature
end if
' Invia l'email
if Len(emailServer) > 0 then
.Send
blnSent = true
end if
end with
Set objMail = Nothing
Set objMailConfig = Nothing
' ****** PERSIT ASPEMAIL *****
case "ASPEmail"
' Crea l'oggetto ASPEMAIL
Set objMail = Server.CreateObject("Persits.MailSender")
with objMail
' SMTP mail server
.Host = emailServer
' SMTP port
.Port = 25
' Mittente
.From = fromEmail
.FromName = fromName
' Destinatario
.AddAddress toEmail, toName
' Oggetto
.Subject = emailSubject
' Corpo dell'email
if isHTML then
.Body = Replace(strBodyFormat, "$body$", emailBody & strBodySignature)
else
.Body = emailBody & strBodySignature
end if
' Imposta il formato HTML
if isHTML then
.IsHTML = true
end if
if Len(emailServer) > 0 then
.Send
blnSent = true
end if
end with
Set objMail = Nothing
' ****** ASPMAIL *****
case "ASPMail"
' Crea l'oggetto ASPMAIL
Set objMail = Server.CreateObject("SMTPsvg.Mailer")
with objMail
' SMTP mail server
.RemoteHost = emailServer
' Mittente
.FromAddress = fromEmail
.FromName = fromName
' Destinatario
.AddRecipient toName, toEmail
' Oggetto
.Subject = emailSubject
' Corpo dell'email
if isHTML then
.BodyText = Replace(strBodyFormat, "$body$", emailBody & strBodySignature)
.ContentType = "text/HTML"
else
.BodyText = emailBody & strBodySignature
.ContentType = "text/plain"
end if
if Len(emailServer) > 0 then
.SendMail
blnSent = true
end if
end with
Set objMail = Nothing
end select
' Infine restituiamo il valore della variabile blnSent prima definita che presumibilmente corrisponderà a true se l'email è stata inviata
sendEmail = blnSent
' e chiudiamo la funzione
end function
' prova richiamo
'myEmail = sendEmail("Destinatario", "destinatario@dominio.com", "Webmaster", "webmaster@sito.com", "Oggetto di prova", "Corpo dell'email", true, "CDONTS", "mail.sito.com")
%>