Forum Moderators: mack
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.
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?
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?
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]
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.
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.
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,