Forum Moderators: mack

Message Too Old, No Replies

Form Submission with asp file

         

ox4dboy

4:36 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Quick (I hope) question:

I have a form on a site, that when submitted calls a .asp file, and than asp file then relays the info to the correct recepient of the email.

What I want to do is, on the Mailer.FromAddress= "..." line below, have the sender's email address show up in the from area. So, the Mailer.FromAddress= "..." needs to get the info from the "Email" field of the form and display that person's email address in the "From:" area of the email when the recieient gets the email.

The ASP file:

<%
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "From the Name of Web site"
Mailer.FromAddress= "I want this to be the sender"
Mailer.RemoteHost = "mail.company.com"
Mailer.AddRecipient "name of Recipient", "recipient@company.com"
Mailer.Subject = "Resumé Submission"
strMsgHeader = "Resumé information follows" & vbCrLf & vbCrLf
for i = 1 to Request.Form.Count
strMsgInfo = strMsgInfo & Request.Form.Key(i) & ": " & Request.Form.Item(i) & vbCrLf
next
strMsgFooter = vbCrLf & "End of resumé information"
strMsgTime = vbCrLf & "Resumé submission time:" & now()
Mailer.BodyText = strMsgHeader & strMsgInfo & strMsgFooter & strMsgTime
if Mailer.SendMail then
Response.Redirect "../thank-you.html"
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
%>

Currently, when the form is submitted, the email that appears in the recipietn's inbox looks like this:

From: From the Name of Web site <I want this to be the sender>

"From the Name of Web site" is generated by the line, Mailer.FromName = "..." and "<I want this to be the sender>" is generated by the line "Mailer.FromAddress= "..."

Anyone have a suggestion? I am very new to asp and form scripting.

RonPK

4:49 pm on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know much about VBscript, but until some guru shows up I'd try this:

change the line

Mailer.FromAddress= "I want this to be the sender"

into

Mailer.FromAddress= Request.Form.Item(5)

Replace the 5 with the right number, i.e. 3 if the email field is the third field in the form.

ox4dboy

5:09 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



RonPK,

Thanks for the quick response. I tried your suggestion, which produced the result below:

From: the Name of Web site" <Request.Form.Item7>

This is how I entered your suggestion into the asp file's code:

Mailer.FromAddress= "Request.Form.Item(7)"

It seems to be taking "Request.Form.Item(7)" literally, instead of carrying out a function?

RonPK

5:50 pm on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Mailer.FromAddress= "Request.Form.Item(7)"

I guess the quotes cause the problem...

ox4dboy

7:06 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



So, I poked around a bit, and got it working using:

Mailer.FromAddress= Request.Form.Item(9)

I do not know why Item(9) worked, since the email field is actually the 7th form field down? I also don't know if this will work on forms where the fields are differnt? I got lucky in guessing (9) after (7) failed, so I guess for other forms I can guess until I get it.

There must be a way to know exactly what to use? If anyone comes across this thread, please help me to understand this a bit better if you can.

Will what I have done work OK, is it acceptable, or should I have done something defferent?

RonPK

1:51 pm on Dec 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Other form elements will be included in the count: hidden fields, buttons, ...

Maybe you could try to expand the loop, wait until the right element comes along and than assign its value to Mailer.FromAddress:

for i = 1 to Request.Form.Count  
strMsgInfo = strMsgInfo & Request.Form.Key(i) & ": " & Request.Form.Item(i) & vbCrLf
if Request.Form.Key(i) = "Email" then
Mailer.FromAddress= Request.Form.Item(i)
end if
next

I normally use PHP, which makes it easy to access a posted value directly: $_POST["Email"]. I guess ASP / IIS also provide such a method, but as I said, I don't know much about it.

Here's some documentation you may find usefull:
Request Form Collection [msdn.microsoft.com]
Using forms and precessing user input [msdn.microsoft.com]

ox4dboy

2:58 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



Thanks for all of your attention and input on this issue. The final solution was pretty simple, I just didn't know about it. "All" I had to do is change the Mailer.FromAddress line to:

Mailer.FromAddress= Request.Form("email")

Changing "email" to any of the other field names works as well if I desire to do so.

You were close on your first suggestion. After the first of the year I am goin to get into PHP, so maybe I/we will be able to impliment that instead of ASP one day?

Thanks again.

txbakers

8:53 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am goin to get into PHP, so maybe I/we will be able to impliment that instead of ASP one day

Why? Just to save a few lines of code? ASP and PhP are comparable dynamic scripting languages.

If you have a Windows server already I'd stick with ASP since it runs natively on IIS.

You can't really say one is better than the other.

People have preferences, but they both return the same data.

ox4dboy

9:23 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



I don't know a whole lot about either, right now. I plan to learn PHP for a number of reasons, but mainly I just like the direction it is going. In the end, I'd like to be able to build my own light weight CMS using PHP. It seems that XHTML + CSS + PHP is better than XHTML + CSS + ASP. I like the way that PHP integrates right into HTML.

I also like the open source movement that PHP is follwoing!

And last, but not least, I am a Mac user. Apache is already installed on all new Macs out of the box. The same might be true for PCs, but that's not my concern. I like Macs, I like PHP, and that's all.

Right now I don't know very much about either, so I really can't defend my decision too mcuh at this point. I am impressed with the PHP driven CMSs out there, and I want to learn more about that...not ASP.

Thanks,