Email Submission Form - Classic Asp

Asked

Viewed 930 times

2

I need help with e-mailing from a form on html.

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

As I am a beginner and until then I only used PHP I’m having trouble turning the section below into a code ASP.

<?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");

?>

3 answers

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" 
%>
  • @I understand that you must be seeing things :D

  • Besides, I didn’t know request(obj), it would have to be request("obj")

  • the request would not be to pick up a form?

  • There is no functional example, my server does not run Asp, but at the time I used Asp was that same

  • good, I don’t want to disturb your code, but I use request only to get sent form value, request type("name")

  • request(variable) I didn’t know

  • but if that’s what it is, it’s news to me... I just wanted to emphasize that request.form is outdated

  • @I read this code at the time who provided me was the staff of the server

  • I work with Asp 11 years ago and only used request to get form post

Show 5 more comments

1


Below is a basic example of sending E-mail with the component CDOSYS 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!!")
%>

0

You can also send by 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")
%>

Heed: Hosting providers block sending in case the email sender does not belong to the domain of the site.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.