צפיות
תשובות
שאלה לגבי שליחת מייל דרך CDOSYS
ברצוני להפוך את השדה של הטלפון לחובה בקוד שמודבק למטה בהודעה זו,
ברצוני שהקוד יוודא שאכן הוקלד מספר טלפון ורק לאחר מכן ישלח את המייל ובמידה ולא הוקלד שלא יבצע כלום (אני יודע איך להפנות לעמוד שגיאה, זו לא המטרה בטופס הנ"ל)
להלן הקוד שלי :
<%
' Dims the email vars
Dim Mailer, Message, Subject, ToAddress, FromAddress, t1name,t1,t2name,t2,t3name,t3,t4name,t4,t5name,t5,t6name,t6,t7name,t7,t8name,t8
t1name = "First Name"
t1 = Request.Form("fname")
t2name = "Last Name"
t2 = Request.Form("lname")
t3name = "Street"
t3 = Request.Form("street")
t4name = "Number"
t4 = Request.Form("strnum")
t5name = "City"
t5 = Request.Form("city")
t6name = "Zip Code"
t6 = Request.Form("mikud")
t7name = "Phone Number"
t7 = Request.Form("phone")
t8name = "Email"
t8 = Request.Form("email")
' Sets CDOSYS ASP Component
Set Mailer = CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
' Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mysite.com"
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") = 60
objCDOSYSCon.Fields.Update
' Update the CDOSYS Configuration
Set Mailer.Configuration = objCDOSYSCon
Mailer.BodyPart.Charset = "windows-1255"
' Creates the Body of the Email
Message = "Hi," & VbCrLf
Message = Message & "You need to use encoding UTF-8 to read hebrew" & VbCrLf
Message = Message & "This Email was sent at "& now() &"" & VbCrLf
Message = Message & "by " & Request.ServerVariables("REMOTE_ADDR") _
& " at " & Request.ServerVariables("REMOTE_HOST") _
& ". Server time: " & time & " " & Date & " " & vbcrlf
' This is the Subjext Line
Subject = "Contact Form"
' This is the To Address
' This Email Address must be an email address
' You have created on your hosting account
ToAddress = "[email protected]"
' This is the From Address
' This Email Address must be an email address
' You have created on your hosting account
FromAddress = "[email protected]"
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
Mailer.TextBody = Message & vbcrlf&_
t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
t3name & vbcrlf&_
t3 & vbcrlf&_
t4name & vbcrlf&_
t4 & vbcrlf&_
t5name & vbcrlf&_
t5 & vbcrlf&_
t6name & vbcrlf&_
t6 & vbcrlf&_
t7name & vbcrlf&_
t7 & vbcrlf&_
t8name & vbcrlf&_
t8 & vbcrlf
' ColSetlects the Subject of the Email
Mailer.Subject = Subject
' Set the To Address of the Email
Mailer.To = ToAddress
' Set the From Address of the Email
Mailer.From = FromAddress
' Mails the Email
Mailer.Send
' Closes Mailer Object
Set objCDOSYSCon = Nothing
set Mailer = Nothing
%>
3 תשובות
תשובה
לפני שאתה יוצר את האובייקט שלך, תוסיף את התנאי הבא:
If Len(t7)<9 Then Response.Redirect "error.asp"
אתה כמובן יכול לעשות בלי הפניה לעמוד ובעצם לעשות תנאי כמו שכתבתי, רק במקום ההפניה לכתוב טקסט מסוים, ואז לכתוב ELSE וכל הקוד של שליחת המייל יהיה בו ואז END IF.
תקרא על משפטי תנאי במדריך ASP.
"החיים הם רק הדרך במסע הנפש", בילד 2004-2008 <img src='/images/6.gif'>
http://Www.Torec.Net * http://Www.Torec.In
שאלת המשך
תודה על התשובה,
אני לא ממש מבין ב-ASP די לומד תוך כדי, ולא מצאתי את המדריך עליו אתה מדבר אבל כמו שרשמתי, אני לא רוצה פקודת redirect לעמוד כלשהו האם אני יכול לרשום פקודה בסגנון :
if Len(t7)<9 the STOP
else
והמשך הקוד ?
ז"א אני פשוט רוצה שלא יקרה כלום במידה ואין טלפון…
מצאתי
תודה על ההכוונה למקום הנכון
זה הפתרון :
If Len(t7)<1 Then
response.end
end if