email send issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kennykenn
    New Member
    • Oct 2007
    • 8

    #1

    email send issues

    Hi,
    Ive producd code to send an email after capturing info off a form,it works fine locally but when i put it live it doesnt work! the code is stopin at 'msg.send' any ideas,

    here the code!





    [CODE=asp]<%
    option explicit

    '---------------------------------------------------------------------------------------------------
    'FORM MAIL SCRIPT
    '----------------
    'usage:
    '<form ACTION="sendmai l_cdo.asp" ...>
    '
    'hidden fields:
    ' redirect - the url to redirect to when the mail has been sent (REQUIRED)
    ' mailto - the email address of the recipient (separate multiple recipients with commas) (REQUIRED)
    ' cc - the email address of the cc recipient (separate multiple recipients with commas) (OPTIONAL)
    ' bcc - the email address of the bcc recipient (separate multiple recipients with commas) (OPTIONAL)
    ' mailfrom - the email address of the sender (REQUIRED)
    ' subject - the subject line of the email (REQUIRED)
    ' message - the message to include in the email above the field values. not used when a template is being used. (OPTIONAL)
    ' template - specifies a text or html file to use as the email template, relative to the location of the sendmail script. (e.g. ../email.txt)
    ' A template should reference form fields like this: [$Field Name$]
    ' html - if this has the value "yes", the email will be sent as an html email. only used if a template is supplied.
    ' testmode - if this is set to "yes", the email contents will be written to the screen instead of being emailed.
    '---------------------------------------------------------------------------------------------------
    dim pde : set pde = createobject("s cripting.dictio nary")
    '---------------------------------------------------------------------------------------------------
    'PREDEFINED ADDRESSES for the "mailto" hidden field
    'if you don't want to reveal email addresses in hidden fields, use a token word instead and specify
    'below which email address it applies to. e.g. <input type="hidden" name="mailto" value="%stratde partment%">
    'ALSO, in the same way, you can use %mailfrom% to hide the originating email address
    pde.add "%contactform%" , "kenny.norris@2 57oops.com"
    pde.add "%salesenquiry% ", "dave@257oops.c om"
    '---------------------------------------------------------------------------------------------------

    function getTextFromFile (path)
    dim fso, f, txt
    set fso = createobject("S cripting.FileSy stemObject")
    if not fso.fileexists( path) then
    getTextFromFile = ""
    exit function
    end if
    set f = fso.opentextfil e(path,1)
    if f.atendofstream then txt = "" else txt = f.readall
    f.close
    set f = nothing
    set fso = nothing
    getTextFromFile = txt
    end function

    dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode
    redir = request.form("r edirect")
    mailto = request.form("m ailto")
    if pde.exists(mail to) then mailto = pde(mailto)
    cc = request.form("c c")
    bcc = request.form("b cc")
    mailfrom = request.form("m ailfrom")
    if mailfrom = "" then mailfrom = pde("%mailfrom% ")
    subject = request.form("s ubject")
    message = request.form("m essage")
    template = request.form("t emplate")
    testmode = lcase(request.f orm("testmode") )="no"

    if len(template) > 0 then template = getTextFromFile (server.mappath (template))
    if len(template) > 0 then usetemplate = true else usetemplate = false
    dim msg : set msg = server.createob ject("CDO.Messa ge")
    msg.subject = subject
    msg.to = mailto
    msg.from = mailfrom
    if len(cc) > 0 then msg.cc = cc
    if len(bcc) > 0 then msg.bcc = bcc

    if not usetemplate then
    body = body & message & vbcrlf & vbcrlf
    else
    body = template
    end if
    for each item in request.form
    select case item
    case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode"
    case else
    if not usetemplate then
    if item <> "mailfrom" then body = body & item & ": " & request.form(it em) & vbcrlf & vbcrlf
    else
    body = replace(body, "[$" & item & "$]", replace(request .form(item),vbc rlf,"<br>"))
    end if
    end select
    next

    if usetemplate then
    dim rx : set rx = new regexp
    rx.pattern = "\[\$.*\$\]"
    rx.global = true
    body = rx.replace(body , "")
    end if

    if usetemplate and lcase(request.f orm("html")) = "yes" then
    msg.htmlbody = body
    else
    msg.textbody = body
    end if
    if testmode then
    if lcase(request.f orm("html")) = "yes" then
    response.write "<pre>" & vbcrlf
    response.write "Mail to: " & mailto & vbcrlf
    response.write "Mail from: " & mailfrom & vbcrlf
    if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
    if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
    response.write "Subject: " & subject & vbcrlf & string(80,"-") & "</pre>"
    response.write body
    else

    response.write "<html><head><t itle>Sendmail_c do.asp Test Mode</title></head><body><pre >" & vbcrlf
    response.write "Mail to: " & mailto & vbcrlf
    response.write "Mail from: " & mailfrom & vbcrlf
    if len(cc) > 0 then response.write "Cc: " & cc & vbcrlf
    if len(bcc) > 0 then response.write "Bcc: " & bcc & vbcrlf
    response.write "Subject: " & subject & vbcrlf & vbcrlf
    response.write string(80,"-") & vbcrlf & vbcrlf & "<span style=""color:b lue;"">"
    response.write body & "</span>" & vbcrlf & vbcrlf
    response.write string(80,"-") & vbcrlf & "**END OF EMAIL**</pre></body></html>"
    end if
    else

    msg.Send
    response.redire ct redir


    end if
    set msg = nothing
    %>[/CODE]
  • epots9
    Recognized Expert Top Contributor
    • May 2007
    • 1352

    #2
    that is asp, there is no javascript.

    the issue could be with the SMTP server.

    Comment

    • kennykenn
      New Member
      • Oct 2007
      • 8

      #3
      what could the problem be?been trying to sort it out for days!! help!!

      Comment

      Working...