PDA

View Full Version : Email info and refering friends


Dr.WiggY
08-05-2003, 04:17 AM
hi well i spoke about something similar in an old post
but here is some code im going to share to ask if anyone would be able to help out with it. It may be an ordering problem or i may be on the wrong path but the idea seems like it should work.

<%
Sub sendref(email as string, nayme as string)
'===================GET EMAIL TEMPLATE======================
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("./data/emailDB.mdb")
Conn.Open
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM template", Conn, 1,3
Do until RS.EOF
emailbody = RS("body")
emailsubject = RS("subject")
from_name = RS("from_name")
from_email = RS("from_email")
RS.movenext
Loop
RS.close
set RS = nothing
set Conn = nothing
'===================SEND MAIL FUNCTION======================
Dim objCDONTS

Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = from_name & " <" & from_email & ">"
objCDONTS.To = email
objCDONTS.Subject = strSubject
objCDONTS.Body = vbcrlf & vbcrlf & emailbody & vbcrlf & vbcrlf & vbcrlf
objCDONTS.Send
Set objCDONTS = Nothing

End Sub

If request.form("ref1_name") > "" & request.form("ref1_email") > "" then
ref1 = true
End if
If request.form("ref2_name") > "" & request.form("ref2_email") > "" then
ref2 = true
End if
If request.form("ref3_name") > "" & request.form("ref3_email") > "" then
ref3 = true
End if

Dim emailaddress
emailaddress = request.form("email")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("./data/emailDB.mdb")
Conn.Open
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "SELECT * FROM emails WHERE email='"&emailaddress&"'", Conn, 1,3
RS.fields("viewed") = true
RS.fields("pos_reply") = true
RS.fields("proceed") = true
If ref1 = true then
RS.fields("ref1_name") = request.form("ref1_name")
RS.fields("ref1_email") = request.form("ref1_email")
send_ref1 = true
End if
If ref2 = true then
RS.fields("ref2_name") = request.form("ref2_name")
RS.fields("ref2_email") = request.form("ref2_email")
send_ref2 = true
End if
If ref3 = true then
RS.fields("ref3_name") = request.form("ref3_name")
RS.fields("ref3_email") = request.form("ref3_email")
send_ref3 = true
End if
RS.update
RS.close
set RS = nothing
set Conn = nothing

If send_ref1 = true then
Call sendref(request.form("ref1_email"), request.form("ref1_name"))
End if
If send_ref2 = true then
Call sendref(request.form("ref2_email"), request.form("ref2_name"))
End if
If send_ref3 = true then
Call sendref(request.form("ref3_email"), request.form("ref3_name"))
End if

Response.redirect "thanks.asp"
%>

that page comes from a page with a form and i have checked all names, variables and links etc.. so try copy and pasting that in a program with some syntax highlighting to get a better understanding and please if anyone wants to know more about or understands what may be wron please let us know
(It returns a HTTP 500 Internal Server Error - the DB link is fine and so is the SQL)

Bullschmidt
08-05-2003, 04:56 AM
You might try switching from CDONTS (which is being phased out) to the newer CDO such as can be seen in the E-mail Attachment example at http://www.asp101.com/samples

whammy
08-07-2003, 01:31 AM
(It returns a HTTP 500 Internal Server Error - the DB link is fine and so is the SQL)

If you're programming in ASP, it's important that you go into tools/internet options/advanced in Internet Explorer and UNcheck the box that says "Show friendly HTTP error messages".

Then, instead of "HTTP 500 Internal Server Error", it will tell you what the real error is - which is usually a lot more helpful. :)

Dr.WiggY
08-07-2003, 03:08 AM
LOL im such an idiot

i thought ticking that was to show the more detailed errors

hehe thanks mate
should be able to debug that now.

whammy
08-07-2003, 03:18 AM
Well, that will help... but ASP generally gives you some pretty cryptic error messages.

Let us know in that case - although they're usually in a SQL Statement when they are hard to figure out, in which case you just want to response.write the SQL Statement out to the ASP page to see what's going on. :D

Dr.WiggY
08-07-2003, 03:27 AM
hehe it was the

Sub sendref(email as string, nayme as string)
---------------------^^^^---------^^^^^
"as string" bits (been using VB too much lately)

The rest seems to work fine.

but CDonts is doing that stupid thing to me again where it only will send when it feels like it.

so im gonna check that CDO thing out

Thanks guys :) :thumbsup:

oracleguy
08-07-2003, 05:42 AM
Make sure you sent the "From" field when you send with CDONTS.

http://support.microsoft.com/default.aspx?scid=kb;en-us;319285

Otherwise your mail won't send.

whammy
08-07-2003, 05:56 AM
Yup... which reminds me, I'm getting a strange error when I try to send to my hotmail account from my machine. I think I can fix it though...