View Full Version : another email question
gcapp
10-01-2002, 12:16 AM
Ok another simple one for somebody.
I have this asp code and my email client doesn't read html format:
StrALL = StrALL & "LastName: " & StrLastName & vbcrlf
StrALL = StrALL & "Organization: " & StrOrganization & vbcrlf
StrALL = StrALL & "Address: " & StrAddress & vbcrlf
StrALL = StrALL & "City: " & StrCity & vbcrlf
StrALL = StrALL & "State: " & StrState & vbcrlf
StrALL = StrALL & "Zip: " & StrZip & vbcrlf
How do I enter a IF....THEN statement, so if someone doesn't fill in a form box (say City), the email will come through without line breaks?
So if i get the email and someone didn't fill in City, the email would look like:
Last Name: Smith
Organization: IBM
Address: 123 street
State: NY
Zip: 14555
No empty line like:
Last Name: Smith
Organization: IBM
Address: 123 street
City:
State: NY
Zip: 14555
Thanks,
Gary
whammy
10-01-2002, 12:27 AM
You're right - it's a simple if/then statement:
StrALL = StrALL & "LastName: " & StrLastName & vbcrlf
StrALL = StrALL & "Organization: " & StrOrganization & vbcrlf
StrALL = StrALL & "Address: " & StrAddress & vbcrlf
If City <> "" Then
StrALL = StrALL & "City: " & StrCity & vbcrlf
End If
StrALL = StrALL & "State: " & StrState & vbcrlf
StrALL = StrALL & "Zip: " & StrZip & vbcrlf
I'm surprised you didn't figure that out yourself, since a simple experiment would have showed that your idea worked perfectly.
Don't be afraid to play around with stuff. You can only break it - but if you know what the code looked like before (hint: save files under another file name before modifying them), then it's a cinch. :)
gcapp
10-01-2002, 12:46 AM
Whammy,
Well I thought what I had in mind would work, but it didn't.
I have my if..then statement as such:
If StrLocState <> "" Then
StrALL = StrALL & "State: " & StrLocState & vbcrlf
End If
it still gives me a line that has
State:----nothing----
Did I do something wrong or does it print the line because of the way I have the email set up? My email code look likes this:
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = strrequired_email
Mailer.FromAddress= strrequired_email
'Mailer.RemoteHost = "mail.enchantedmountains.info"
Mailer.RemoteHost = SMTP_SERVER
Mailer.AddRecipient ToName, ToEmail
'Mailer.AddCC "Gary Cappelletti","gacapp@adelphia.net"
Mailer.Subject = "NYS Database Contact Form"
Mailer.BodyText = StrALL
Mailer.SendMail
I'm kind of confused.
whammy
10-01-2002, 12:49 AM
Perhaps you aren't formatting your email by the variables that were entered?!? (Or is it possible that you have modified the script on your local machine, and not refreshed the server-side page once you corrected and uploaded it?)
Not to mention, you changed the variable name you were testing from:
"City"
to
"State"
... I'd stick with one variable while you're troubleshooting a problem - for simplicity's sake.
Also, if any of these variables are used in subroutines, make sure you Dim (Dimension) them (or they are a Constant instead). Otherwise the value of the variable will not be passed to a sub.
If you're still running into problems, I'd post the complete code here. I'm sure the answer will be obvious if enough people look at it . ;)
P.S. Also if you are using subroutines, make sure that you have:
<% Option Explicit %>
at the top of your page after the "Language" tag.
I've run into a lot of situations where people coded script perfectly, but didn't get any values since they were not dimensioned, and no errors because Option Explicit was not in place.
gcapp
10-02-2002, 01:46 PM
Well for some reason, it just won't work. At the bottom of this note is the code I used. I didn't put any of the form part in here because the form is huge. And I only put a few lines of each asp code, again because the form is huge.
If someone can see why this script will not produce a breaked line when there is no information entered, please let me know.
<%@ Language=VBScript %>
<%Option Explicit%>
<%Session("GotFlash") = true%>
<%Response.Buffer = true%>
<!-- #include file=inc_header.asp -->
<% Dim StrLocState, StrLocCounty, StrLocRegion, StrLocCity, StrEventName, StrEventDescription, StrSiteAddress
ToName, ToEmail, Mailer, SMTP_SERVER, StrALL %>
<%
'Check if form is sent or not.
If Request.Form("posted") = "True" Then
'This code is getting the information from the form that was posted and it will be stored into a valeable for use.
StrLocState = Request.Form("LocState") & " "
StrLocCounty = Request.Form("LocCounty") & " "
StrLocRegion = Request.Form("LocRegion") & " "
StrLocCity = Request.Form("LocCity") & " "
StrEventName = Request.Form("EventName") & " "
StrEventDescription = Request.Form("EventDescription") & " "
'Name of Mail server used for ASPMail
SMTP_SERVER = "mail.enchantedmountains.info" 'alentus
'This is the string of text that will be sent to you through e-mail.
StrALL = StrALL & uCase("Event Location") & vbcrlf
If StrLocState <> "" Then
StrALL = StrALL & "State: " & StrLocState & vbcrlf
End If
StrALL = StrALL & "Region: " & StrLocRegion & vbcrlf
StrALL = StrALL & "Country: " & StrLocCounty & vbcrlf
StrALL = StrALL & "City: " & StrLocCity & vbcrlf
StrALL = StrALL & uCase("Event Name: ") & StrEventName & vbcrlf
StrALL = StrALL & uCase("Event Description: ") & StrEventDescription & vbcrlf
If Request.ServerVariables("HTTP_HOST") <> "alentus" then
'Send Mail to Administrator
ToName = "Enchanted Mountains Region"
ToEmail = "visitor@enchantedmountains.info"
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = strrequired_email
Mailer.FromAddress= strrequired_email
'Mailer.RemoteHost = "mail.enchantedmountains.info"
Mailer.RemoteHost = SMTP_SERVER
Mailer.AddRecipient ToName, ToEmail
'Mailer.AddCC "Gary Cappelletti","gacapp@adelphia.net"
Mailer.Subject = "NYS Database Contact Form"
Mailer.BodyText = StrALL
Mailer.SendMail
End If
'This line of code will take the person that submited the form to the page entered as a string. You might want to make a submition page so thge use knows it was sent succesfully. :)
Response.Redirect("contact_us_thanks.asp")
End If%>
gcapp
10-03-2002, 12:26 AM
Whammy or someone--
can anyone see why the code I have submitted on the previous post would not skip a line in my email message??
It still gives me the lead in part.
In the previous post code the result still gives:
State:
County: Catt
Region: West
As you can see it still shows the "State:" line, even though there was nothign entered in the form.
Help!!
whammy
10-03-2002, 12:41 AM
Doh... I see the problem. And here it is:
StrLocState = Request.Form("LocState") & " "
Since you're adding a space to the variable, it's not equal to "" (empty).
I don't see why you'd want to do that anyway... get the variable as is (not just email, but all of them), like:
StrLocState = Trim(Request.Form("LocState"))
(Not to mention that's just completely unnecessary.)
And then add spaces to the message itself (not the variable!) if you want them in there later (which really you don't need at all, since you're using vbCrLf).
:)
gcapp
10-03-2002, 02:16 PM
Someone help - please!!!!!!
From the previous post, Whammy said to change the code in my email and now the form will not send email. It appears as if it does, but I do not receive any. It worked before, but since I mad the changes it does not.
I won't put the whole form here because it's huge, but here are the excerpts of what I changed:
If Request.Form("posted") = "True" Then
'This code is getting the information from the form that was posted and it will be stored into a valeable for use.
StrLocState = Trim(Request.Form("LocState"))
StrLocCounty = Trim(Request.Form("LocCounty"))
SMTP_SERVER = "mail.enchantedmountains.info" 'alentus
'This is the string of text that will be sent to you through e-mail.
StrALL = StrALL & uCase("Event Location") & vbcrlf
If StrLocState <> "" Then
StrALL = StrALL & "State: " & StrLocState & vbcrlf
End If
If StrLocRegion <> "" Then
StrALL = StrALL & "Region: " & StrLocRegion & vbcrlf
End If
If StrLocCounty <> "" Then
StrALL = StrALL & "Country: " & StrLocCounty & vbcrlf
End If
If Request.ServerVariables("HTTP_HOST") <> "alentus" then
'Send Mail to Administrator
ToName = "Enchanted Mountains Region"
ToEmail = "visitor@enchantedmountains.info"
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = strrequired_email
Mailer.FromAddress= strrequired_email
'Mailer.RemoteHost = "mail.enchantedmountains.info"
Mailer.RemoteHost = SMTP_SERVER
Mailer.AddRecipient ToName, ToEmail
'Mailer.AddCC "Gary Cappelletti","gacapp@adelphia.net"
Mailer.Subject = "NYS Database Contact Form"
Mailer.BodyText = StrALL
Mailer.SendMail
End If
Is it not sending mail becuase all fields need to be filled out now??
gcapp
10-03-2002, 02:28 PM
Ok, I figured why it wouldn't send email and that is becuase all fields were not filled out. Now that is what I don't want. There are optional fields that do not need to be filled out.
My goal here was to have the email skip the blank lines, so the email would not be so long.
When I first changed it, I only changed one line of code and it worked correctly, so since it worked fne, I did the change for all the code and now it makes me fill in all the parts of the form, which is not necessary.
Now I can go back to the way I had it but the email comes through with every line, even if the form box isn't filled in, like this:
State:
City: New York
Zip:
Occupation:
I want the email to come through and skip those line that nothign was entered into the form box, so in the previous example only the City line would be on the email.
Can anyone see why my code is making me fill out every form box?
whammy
10-04-2002, 02:15 AM
That would be in the validation code that you wrote, would it not?
Just don't validate for the fields if you don't care if they are empty...
:eek:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.