ASP Sending Mail - email

I am a beginner at ASP programming. I am trying to figure out a simple script to send an email. This is my HTML Code:
<form method="POST" action="email.aspx">
To <input type="text" name="To"/> <br />
From <input type="text" name="From"/> <br />
Subject <input type="text" name="Subject"/> <br />
Body <textarea name="Body" rows="5" cols="20" wrap="physical" >
</textarea>
<input type="submit" />
</form>
This is my ASP code:
Dim mail
mail = Server.CreateObject('CDO.Message')
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
mail.Send()
Response.Write("Mail Sent!")
mail = Nothing
I know the set method is no longer supported, I am getting errors with the ASP code, are there any solutions to sending a simple email in ASP? Thank you all in advance!

Your code will only work if CDO or CDONTS is installed and available on your server - though most webhosts that support Classic ASP will make this available.
In VBScript, all objects (i.e. things that aren't numbers or strings) must be assigned using the Set operator. It's silly, I know, but this is what you need to do:
Dim mail
Set mail = Server.CreateObject("CDO.Message")
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
mail.Send
Response.Write "Mail Sent!"
Set mail = Nothing
If your server doesn't have CDO or CDONTS installed then you'll get an error message when you call CreateObject, but you haven't listed any error messages in your original question.

Related

Coldfusion - Form submission somehow different on mobile?

So I have a very strange problem. I have a simple form setup to collect email / password. On the submission page I run these through a query to check if the user exists. This all works fine on desktop, but using it on mobile results in the query always returning 0 for record count.
<form action="test2.cfm" method="post">
<input type="hidden" name="lang" value="EN">
Email Address : <input type="text" name="strEmail" style="width: 200px;">
Password : <input type="password" name="strPassword" style="width: 200px;">
<br /><input type="submit" value="LOGIN"></td>
</form>
<cfquery name="getParticipant" datasource="#request.dbDSN#" username="#request.dbUsername#" password="#request.dbPassword#">
SELECT * FROM mytable
WHERE email = <cfqueryparam value="#FORM.strEmail#" cfsqltype="CF_SQL_VARCHAR">
AND password = <cfqueryparam value="#FORM.strPassword#" cfsqltype="CF_SQL_VARCHAR">
</cfquery>
<cfoutput>
record count: #getParticipant.recordCount#
</cfoutput>
As I've stated this code works fine when an existing user attempts to login on a desktop computer. The EXACT same code returns 0 when a login is attempted on mobile.
What is going on???

problems with classic asp if statment and reading form values

I have been having trouble with a bit of classic asp code
pretty much what I want to do is when a hidden field has a value of 1 a message is displayed
here is the code i have:
<% if (CStr(Request.form("HiddenLog")) = CStr("1")) then %>
<br /> <p style="color:Red;">Message here</p>
<%end if %>
<input type="hidden" id="HiddenLog" value="1" />
The result is nothing appears on screen however if I add an else to the if statment like so
<% if (CStr(Request.form("HiddenLog")) = CStr("1")) then %>
<br /> <p style="color:Red;">Message here</p>
<%else%>
<br /> <p style="color:Red;">Message here</p>
<%end if %>
The message always appears (of course this was to prove that the if statment is working and that the problem most likly is with getting the form values), can someone please tell me what it is I have done wrong
Thanks
Edit A couple of people have asked about my form so I will post that here as well
<form id="form1" method="post">
all the controls are contained inside this form
you have to give the input field a name attribute. you only have an id attribute this is not posted so just use
<input type="hidden" id="HiddenLog" name="HiddenLog" value="1" />

How long does CFmail take to send?

I am making an app that creates a custom PDF, mails it and then deletes it. I have tested all 3 components separately and they work but when I put them together the email doesn't send.
Is it possible that the attachment gets deleted before the email is sent even though the delete is after it in the script?
Here is my code.
<!---Get the PDF--->
<cfscript>
PDFBuilder = createobject("component", "form_admin.email.PDFBuilder" );
pdf = PDFBuilder.createPDF(form_id);
</cfscript>
<!---Create link to the pdf --->
<cfscript>
foo = expandPath('../email/tmp/') & pdf & '.pdf';
</cfscript>
<!---Create email--->
<cfmail to="will#hazardousfrog.com"
from="will#hazardoufrog.com"
subject="Jag intrest form. "
type="text/html" >
<cfmailparam file="#foo#">
Dear #getEmail.title#, #getEmail.first_name# #getEmail.surname# <br />
Attached is a PDF boucher telling you more information about the cars you were interested in. <br />
Best wishes <br />
Jaguar <br /><br /><br /><br /><br /><br /><br /><br />
This is not actually jaguar this is a test application by Hazardousfrog.
</cfmail>
<!---Delete the file after it has been sent --->
<cfif FileExists(#foo#)>
<cffile action="delete"
file="#foo#">
<cfelse>
<cfoutput >
error
</cfoutput>
<cfabort>
</cfif>
Sorry if the code isn't great I have only been doing CF for like 2 weeks.
Ok I managed to get the answer from a work friend.
When cfmail is processed the mail is saved into a spool and periodically sent out after about 3 mins.
In my case it meant that the email PDF attachment was being deleted before the message could be sent so the mail was not sending.
The coldFusion mail tag has an attribute to send it straight away or keep it spooled.
spoolenable : Whether to spool mail or always send it Immediately.
So to get it to get my code to work I added this line to my mail attributes.
spoolenable="false"
One other option would be to use the remove attribute of the cfmailparam tag which will tell CF to remove the file after it is sent. This way your spoolenable attribute can be true and it should work as desired. The remove attribute was introduced in version 8.0.1.
I would also place a fileExists() around the cfmail code on whether the pdf file indeed has been created.

Typo3 and Mailformplus - form not showing

I have a client with an existing Typo3 site but I'm completely new to the CMS.
I need to add an email signup form. The site already has Mailformplus installed for the contact form.
I've added the plugin to the page. Uploaded an HTML template, and modified a copy of the Typoscript that (I think) is required in a new template.
The title for the form appears (from the plugin record) but none of the form elements. Not even an error.
What have I missed? Where should I look?
HTML:
<!-- ###TEMPLATE_FORM### begin -->
<div class="mailformplus_contactform">
###ERROR###
<form name="Formular" method="post" action="###REL_URL###" enctype="multipart/form-data">
<fieldset>
<legend>###LLL:legend###</legend>
<input type="hidden" name="id" value="###PID###" />
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="L" value="###value_L###" />
<input type="hidden" name="type" value="###value_type###" />
<label for="name">###LLL:name######required_name###</label>
<input type="text" name="name" id="name" value="###value_name###" />
<label for="company">###LLL:company###</label>
<input type="text" name="company" id="company" value="###value_company###" />
<label for="email">###LLL:email######required_name###</label>
<input type="text" name="email" id="email" value="###value_email###" />
<p>###LLL:required_fields###</p>
<input type="submit" value="###LLL:submit###" />
</fieldset>
</form>
</div>
Typoscript:
plugin.tx_thmailformplus_pi1 {
correctRedirectUrl = 1
# emailHeader =
langFile = fileadmin/template/xtra/mailformplus-locallang.xml
}
plugin.tx_thmailformplus_pi1.fieldConf {
name.errorCheck = required
company.errorCheck = required
email.errorCheck = required, email
}
### INFO #################################################
# BETREFF und Empfänger / Config extra von Mailformplus. #
# Mit Listenansicht auf die Contactseite. #
##########################################################
plugin.tx_thmailformplus_pi1.default {
email_to = simon.boak#gmail.com
email_subject = Newsletter Subscription
email_sender = simon.boak#gmail.com
email_redirect = 90
email_requiredfields =
email_htmltemplate =
email_replyto =
email_sendtouser = email
email_subject_user = TEXT
email_subject_user.value = Danke für Ihre Anfrage bei Company
email_subject_user.lang.en = Thank you for your request at Company
}
Set plugin.tx_thmailformplus_pi1.debug = 1
Your setup is really missing the template-setting
Your HTML is missing <!-- ###TEMPLATE_FORM### end --> at the end of the form.
As of point 5 in Matengs answer: Rather than reinstalling mailformplus (which is obsolete and not maintained anymore) use formhandler which is the successor of mailformplus
1.
Start checking the source code of the frontend output. Does it contain parts of your HTML template? (e.g. class="mailformplus_contactform").
2.
If not, make sure the path to the template is correct. It is set in:
plugin.tx_thmailformplus_pi2.template
If the path is correct, the source code of the template should be displayed at least.
3.
Did the extension installation finish successfully? Many extensions won't work if the necessary database tables didn't install properly. You can check in the extension manager.
4.
Furthermore, use the typoscript object browser (in module template) to verify that TYPO3 "accepted" your typoscript setup. Make sure you are on the page where you inserted the mailformplus plugin. Use the search field for that. Maybe your modified typoscript gets overridden somewhere. More hints on debugging typoscript.
5.
If that does not help, backup your current configuration and try to install mailfomrplus from the scratch - does it work when you don't use an individual configuration ?
6.
Come back here to discuss your results.

Form post asp classic xmlhttp

I'm trying to do a form post from another site that is not mine, but
I am not able ta give error.
There on the site the post is mounted like this:
Veja o resultado da enquete anterior »
<br /><br />
<form name="result" action="http://enquete.terra.com.br/enquete.cgi" method="post">
<input type="hidden" name="id_enquete" value="144143">
<input type="hidden" name="opcao" value="0">
</form>
And I'm riding in the asp script to make this post as:
<%
Dim objHttp
Dim str
str = "id_enquete=144143&opcao=0"
Set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHttp.Open "POST", "http://enquete.terra.com.br/enquete.cgi", false
objHttp.setRequestHeader "Host", "http://enquete.terra.com.br"
objHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"
objHttp.setRequestHeader "Content-Length", Len(str)
objHttp.Send str
Response.Write(objHttp.ResponseText)
Set objHttp = nothing
%>
But not this working, does anyone know how or know where I am
wrong??
Thanks
You can't make cross domain request using AJAX due to the same origin policy. If the other site supports JSONP, you can use a script request to access the site and get data from it, of course, your parameters need to be in the URL for that to work.
<script type="text/javascript">
function resultCallback( data ) {
// do something with the returned JSON data
}
</script>
<script type="text/javascript" src="http://enquete.terra.com.br/enquete.cgi?id_enquete=144143&opacao=0&callback=resultCallback">
</script>
Code looks true; the reason why you get "Internal Server Error" is because your IIS settings for error is not in the debug mode.
You should change your IIS settings to "Send error messages to Browser" then you can see the actual error message on the browser; which is probably caused by version of the Msxml2.ServerXMLHTTP object.