Email sending form - classic asp

2

I need help with sending e-mail from a form with html .

The form is already ready and I had a PHP code that was sending this, however the client server is not accepting the PHP code and I need to change it to ASP .

As I am a beginner and until then I had only used PHP I am having trouble transforming the following code into a ASP code.

<?php

$email=$_POST['email'];

$assunto=$_POST['assunto'];

$menssagem=$_POST['texto'];

$Destinatario="[email protected]";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: " . $_POST["email"] . "<" . $_POST["email"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";

mail($Destinatario, $assunto, $menssagem, $headers);

header("Location: index.html");

?>
    
asked by anonymous 05.12.2017 / 17:33

3 answers

1

Below is a basic example of sending Email with the CDOSYS component of the classic asp.

<%@LANGUAGE="VBSCRIPT"%>

<%
'Passo 1: Criar o objeto CDO.Message
Dim objMail 
Set objMail = Server.CreateObject("CDO.Message")

'Passo 2: Configurar o usuário e senha para autenticação SMTP
Dim smtpServer, seuEmail, suaSenha
smtpServer = "smtp.office365.com"
seuEmail   = "[email protected]" 
suaSenha   = "teste@#Teste87761"  

'Passo 3: armazenar o e-mail de quem receberá a mensagem.
enviarEmailPara = "[email protected]"

'Passo 4: Configurar as propriedades do objMail(porta, servidor...)
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = seuEmail
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = suaSenha
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

'Passo 5: Atualizar a configuração após definir as propriedades
objMail.Configuration.Fields.Update

'Passo 6: Preparar o e-mail
Dim assunto, mensagem
assunto  = "Pesquisa de satisfação"
mensagem = "Olá, essa respota lhe foi útil?</br>"
mensagem = mensagem & " Att., Caique Romero"

objMail.From      = seuEmail'Configuro o emitente
objMail.To        = enviarEmailPara 'Configuro o destinatario
objMail.Subject   = assunto
objMail.htmlBody  = mensagem

'Passo 7: Enviar o e-mail
objMail.Send 

'Passo 8: Limpar o objeto
Set objMail = Nothing 

Response.Write("E-mail enviado com sucesso!!")
%>
    
06.12.2017 / 13:13
1
objArray = Array ("email","assunto","texto")

For Each obj In objArray
    strMessage = strMessage & obj & " : " & Request(obj) & "<br>"
Next

'################### Na época que eu usava asp ###################
'------ utilizava este código para envio -----------

        Set objCDOSYSMail = Server.CreateObject("CDO.Message")  
        Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")  
        objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"  
        objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")= 25  
        objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
        objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30 
        objCDOSYSCon.Fields.update  
        Set objCDOSYSMail.Configuration = objCDOSYSCon  
        objCDOSYSMail.From = email   
        objCDOSYSMail.To = "<" & destinatario & ">"    
        objCDOSYSMail.Subject = assunto   
        objCDOSYSMail.HtmlBody = "<p>" & strMessage & "</p>" 
        objCDOSYSMail.Send  
        Set objCDOSYSMail = Nothing 
        Set objCDOSYSCon = Nothing

'outros scripts de envio de email podem ser vistos no link abaixo
'https://www.baboo.com.br/tutorial/tutorial-software/envio-de-e-mail-com-asp/
'#################################################################


if err.number <> 0 then
    response.write "Problemas no envio, por favor tente mais tarde."
else
    response.redirect("index.html")
end if

CDOSys - Authenticated Email Submission - source >

<% 
objArray = Array ("email","assunto","texto")

For Each obj In objArray
    strMessage = strMessage & obj & " : " & Request.Form(obj) & "<br>"
Next


'CRIA A INSTANCIA COM O OBJETO CDOSYS 
Set objCDOSYSMail = Server.CreateObject("CDO.Message") 

'CRIA A INSTANCIA DO OBJETO PARA CONFIGURAÇÃO DO SMTP 
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") 

'SERVIDOR DE SMTP 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.seudominio" 

'PORTA PARA COMUNICAÇÃO COM O SERVIÇO DE SMTP 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587

'Utilização de SSl 
'objCDOSYSCon.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'ATIVAR RECURSO DE SMTP AUTENTICADO 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 

'USU?RIO PARA SMTP AUTENTICADO 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 

'SENHA DO USUÁRIO PARA SMTP AUTENTICADO 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "senha" 

'TEMPO DE TIMEOUT (EM SEGUNDOS) 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 

'ATUALIZA A CONFIGURAÇÃO DO CDOSYS PARA ENVIO DO E-MAIL 
objCDOSYSCon.Fields.update 
Set objCDOSYSMail.Configuration = objCDOSYSCon 

'NOME DO REMETENTE, E-MAIL DO REMETENTE 
objCDOSYSMail.From = "Remetente <[email protected]>" 

'NOME DO DESINATARIO, E-MAIL DO DESINATÁRIO 
objCDOSYSMail.To = "NOME <[email protected]>"
'objCDOSYSMail.cc = "Copia <[email protected]>" 
'objCDOSYSMail.bcc = "Copia Oculta <[email protected]>" 


'ASSUNTO DA MENSAGEM 
objCDOSYSMail.Subject = " Envio autenticado - CDOSYS Apps" 

'CONTEUDO DA MENSAGEM 
objCDOSYSMail.TextBody = strMessage 
'PARA ENVIO DA MENSAGEM NO FORMATO HTML, ALTERE O TextBody PARA HtmlBody 

'objCDOSYSMail.HtmlBody = "<html> <head><meta http-equiv=""Content-Type"" content=""text/html;charset=utf-8""></head><body></body></html>" 

'ENVIA A MENSAGEM 
objCDOSYSMail.Send 

'DESTROI OS OBJETOS 
Set objCDOSYSMail = Nothing 
Set objCDOSYSCon = Nothing 

response.write "Email enviado com sucesso" 

'Response.Redirect "index.html" 
%>
    
06.12.2017 / 06:41
0

You can also send the AspEmail component without authentication:

<%
set AspEmail = Server.CreateObject("Persits.MailSender")
AspEmail.Host = "smtp.dominio.com.br"
AspEmail.FromName = "Nome do remetente"
AspEmail.From = request("email") 'email do remetente
AspEmail.AddReplyTo request("email") 'email do remetente
AspEmail.AddAddress "[email protected]" 'destinatário
AspEmail.Subject = request("assunto")
AspEmail.IsHTML = True 'se a mensagem tiver HTML
AspEmail.Body = request("texto")
AspEmail.Send
response.redirect("index.html")
%>
  

Attention: hosting providers block the sending if the email from the   sender does not belong to the site domain.

    
07.12.2017 / 05:08