Formatted email

i just realised that creating an email with html formatting is alot harder than i thought. A while a go i copied some html code to be sent as an email. I presumed that the email server would read the html and produce the desired page accordingly. Man was i wrong, all i got back was an email with lots html code in it. NO pics or background colors or nothin.

I guess my question is, how do u send an email with html formating that will get it looking like an electronic newsletter?

all suggestions appreciated

well it depends on what langauge your writing your code in. not sure how to do it with php. asp is pretty simple

something like this will work


Set MailObj = Server.CreateObject("CDONTS.NewMail")
MailObj.BodyFormat =  1
MailObj.MailFormat = 0

o no, i dont understand one thing here, could u give me a little more explanation please. I’ve never used asp or php before!

I hope im not asking for 2 much!

thanks

lol no problem, but first, what are you using, php or asp?

whad’ya mean which one am i using. If ur refering to which my server supports then i dont know? but if u mean my preference (which i doubt) i’ll go with watever u say man. since u said said asp is easier i’ll go with that!

lol
thanx

ok well you need to find out what your server supports first, but here’s something small that should help you out

http://www.kirupaforum.com/forums/showthread.php?threadid=28108&highlight=variables+asp

okay, i have asp support so shoot away!

http://www.webmasterworld.com/forum47/196.htm
http://www.4guysfromrolla.com/webtech/faq/Email/faq6.shtml

2 great resources for asp codeing. they can explain it much better than i can

thanks man, really appreciate the help. like someone said in one of the linked sites

paraphrased - "Maybe oneday when i have 1000+ posts i’ll be able 2 dispense advise 2

no problem, did you figure it all out?

actually, no! im dont get something very important; (dont think this is a stupid question but…) what does the code have to do with my server?

well not sure if this is what you mean but, servers allow certain coding languages. since this is asp, your server needs to have IIS to run it. you cannot test this locally, meaning on your pc unless you install IIS

here’s a little soemthing about IIS
|------------------------copy and paste from previous thread----------------|

i hope you know you can not just run an asp page from it’s current location. you need to configure IIS (Internet Information Server) it’s stored under admin options on your start menu. also you will need to configure your SMTP mail server on your machine. I woudl consider signing up for a free account with brinkster http://www.brinkster.com just to get it working then configure your own machine. also i windows millinium doesn’t support IIS Hope you know what i am talking about, if not let me know and I will explain further.

to run an asp file go tto your browser and type
http://localhost/yourpage.asp

run a quick test to see if it’s configured. create an asp page and apply this code

<% response.write "Test" %>


when you call the page as i advised if you dont see test, you don’t have IIS configured properly or you might not have it installed

well the test thing worked so that must mean im on the right track, right
:slight_smile:

yup, did you try apply the code to your project? if you’d like post your html form and asp script, and i’ll take a look at whats going on over there

okay another question, hopefully this will help me even more. Could u xpln how the whole process of sending html email works especially as it relates to this asp server thing plz or direct me to a site that does. i work alot better when i understand complete processes !

thnx much man, i **genuinely appreciate[/] the help u’ve given so far.

edit: dont think i haven read ur previous post. When i say xpln, i mean in “the idiots guide to html email” type of english. lol

lol sure, i can explain but not right now, real busy at work. ill be hom ein about 2 hours and i will explain as best as i can. if you’d like do a search on google for CDONTS, or EMAIL ASP. in short CDONTS is a asp component that allows users to send an email from a web application instead of opening up outlook or another email client. what were doing is taking infomation from an html or flash form and sending to an asp page which then sends an email to a specified user. so the server is sending the email. hope that helped :slight_smile:

okay, i posted the following the asp unto my server.

<%
  Dim objMail
  Set objMail = Server.CreateObject("CDONTS.NewMail")
   
  '//these are all the images that are in this message.
  '//you must include them like this.
  '//please note that you DO NOT have TO write the
  '//entire file path in the <IMG> tag in the body after this.
  '//make sure you see the image name after the path separated by a comma
   
  objMail.AttachURL "D:\images\myImage.gif", "myImage.gif" 
  objMail.AttachURL "D:\images\myImage2.gif", "myImage2.gif" 

 
  HTML = HTML & "<HTML>"
  HTML = HTML & "<HEAD>"
  HTML = HTML & "<TITLE>Send Mail with HTML</TITLE>"
  HTML = HTML & "</HEAD>"
  HTML = HTML & "<BODY  bgcolor=""lightyellow"">"
  HTML = HTML & "<TABLE cellpadding=""4"">"
  HTML = HTML & "<TR><TH><FONT color=""darkblue""  SIZE=""4"">"
  HTML = HTML & now() & " - "
  HTML = HTML & "These are all great ASP Sites</FONT></TH></TR>" 
  HTML = HTML & "<TR><TD>"
  HTML = HTML & "<A HREF=""http://www.4guysfromrolla.com"">"
  HTML = HTML & "<IMG SRC=""myImage.gif""></A><BR><BR>"
  HTML = HTML & "<A HREF=""http://www.4guysfromrolla.com"">"
  HTML = HTML & "<IMG SRC=""myImage2.gif""></A><BR><BR>"
  HTML = HTML & "</FONT></TD></TR></TABLE><BR><BR>"
  HTML = HTML & "</BODY>"
  HTML = HTML & "</HTML>"
  
  objMail.From = "t@zawdie.com"
  objMail.Subject = "Your daily HTML Mail"
      
  'you need TO add these lines FOR the mail
  'to be sent in HTML format
  objMail.BodyFormat = 0 
  objMail.MailFormat = 0 

  objMail.To = "wormybart@yahoo.com"
  objMail.Body = HTML
  objMail.Send
  
  Response.write("Mail was Sent")
  set objMail = nothing
%>

when i accessed the page i saw this.

Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/test/emailtest.asp, line 3

800401f3 


ur analysis plz. what am i doing wrong, am i doing anything right?
thnx much!

forget that, i found this code on aspmessageboard.com and when uploaded it to my server
http://www.zawdie.com/test/emailtest3.asp
everything seemed to work fine. when i put my email in the email box provided, and clicked send, the browser showed “page not found”. Does this mean that i need to have my (or any email addresses im planning to send my email to) in a database on my server.
holds head at thought that he knows litte about databases lol

anyway, heres i the code i used

<%
Dim strTo, strSubject, strBody 'Strings for recipient, subject, boby
Dim objCDOMail 'The CDO object


'First we'll read in the values entered
strTo = Request.Form("to")

'These would read the message subject and body if we let you enter it
'strSubject = Request.Form("subject")
'strBody = Request.Form("body")

' Both of these should be changed before you run this script.
strSubject = "Sample E-mail sent from ASP 101!"

' This is multi-lined simply for readability
strBody = "This message was sent from a sample at http://www.asp101.com.  "
strBody = strBody & "It is used to show people how to send e-mail from an "
strBody = strBody & "Active Server Page.  If you did not request this "
strBody = strBody & "e-mail yourself, your address was entered by one of "
strBody = strBody & "our visitors.  We do not store these e-mail addresses."
strBody = strBody & "  Please address all concerns to [email]webmaster@asp101.com[/email]."

' Some spacing:
strBody = strBody & vbCrLf & vbCrLf

strBody = strBody & "This was sent to: "

' A lot of people have asked how to use form data in the emails so
' I added this line to the sample as an example of incorporating form
' data in the body of the email.
strBody = strBody & Request.Form("to")

' A final carriage return for good measure!
strBody = strBody & vbCrLf


If strTo = "" Or Not IsValidEmail(strTo) Then
    %>
    <FORM ACTION="email.asp" METHOD="post">
        Enter your e-mail address:

        <INPUT TYPE="text" NAME="to" SIZE="30"></INPUT>

        <!--  These would be used if we decided to let you edit them
        Subject: 
        <INPUT TYPE="text" NAME="subject" SIZE="30"></INPUT>

        
        Message: 
        <TEXTAREA NAME="body" ROWS="10" COLS="40" WRAP="virtual"></TEXTAREA>

        -->

        <INPUT TYPE="submit" VALUE="Send Mail!"></INPUT>
    </FORM>
    <%
Else
    ' Create an instance of the NewMail object.
    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
    
    ' Set the properties of the object
    
    ' This syntax works fine
    'objCDOMail.From = "user@domain.com"
    ' But this gets you the appearance of a real name!
    objCDOMail.From    = "User Name <admin@richard.com>"
    objCDOMail.To      = strTo
    objCDOMail.Subject = strSubject
    objCDOMail.Body    = strBody

    ' There are lots of other properties you can use.
    ' You can send HTML e-mail, attachments, etc...
    ' You can also modify most aspects of the message
    ' like importance, custom headers, ...
    ' Check the documentation for a full list as well
    ' as the correct syntax.

    ' Some of the more useful ones I've included samples of here:
    'objCDOMail.Cc         = "user@domain.com;user@domain.com"
    'objCDOMail.Bcc        = "user@domain.com;user@domain.com"
    'objCDOMail.Importance = 1 '(0=Low, 1=Normal, 2=High)
    'objCDOMail.AttachFile "c:\path\filename.txt", "filename.txt"

    ' I've had several requests for how to send HTML email.
    ' To do so simply set the body format to HTML and then
    ' compose your body using standard HTML tags.
    'objCDOMail.BodyFormat = 0 ' CdoBodyFormatHTML
    
    'Outlook gives you grief unless you also set:
    'objCDOMail.MailFormat = 0 ' CdoMailFormatMime

    ' THIS LINE SHOULD BE UNCOMMENTED TO ACTUALLY SEND THE
    ' MESSAGE.  PLEASE BE SURE YOU HAVE APPROPRIATE VALUES
    ' FOR TO AND FROM ADDRESSES AND HAVE CHANGED THE MESSAGE
    ' SUBJECT AND BODY BEFORE UNCOMMENTING THIS.
    ' Send the message!
    objCDOMail.Send
    
    ' Set the object to nothing because it immediately becomes
    ' invalid after calling the Send method.
    Set objCDOMail = Nothing

    'Response.Write "Message sent to " & strTo & "!"
    Response.Write "Message ARE NO LONGER BEING SENT because of all the abuse the system was receiving!"
End If
' End page logic
%>

<% ' Only functions and subs follow!

' A quick email syntax checker.  It's not perfect,
' but it's quick and easy and will catch most of
' the bad addresses than people type in.
Function IsValidEmail(strEmail)
    Dim bIsValid
    bIsValid = True
    
    If Len(strEmail) < 5 Then
        bIsValid = False
    Else
        If Instr(1, strEmail, " ") <> 0 Then
            bIsValid = False
        Else
            If InStr(1, strEmail, "@", 1) < 2 Then
                bIsValid = False
            Else
                If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
                    bIsValid = False
                End If
            End If
        End If
    End If

    IsValidEmail = bIsValid
End Function
%> 

i should add that the name of the page that i was directed to was called “email” as in http://www.zawdie.com/test/email.asp

i put the actual contents of the email i wanted to send in this location. Somehow i know i’m doing the wrong thing.

i await ur response, great gur.
thnx

well you confused me . copy this code and call it test to see if you mail server is confgered. just change the email to go to you



<%


Dim EmailFromAddress, EmailToAddress, Subject, Body, File, strComments

EmailFromAddress = "admin@delusionalfx.com"
EmailToAddress = "sosicK@digitalosophy.com"
Subject = "Test"


Set MailObj = Server.CreateObject("CDONTS.NewMail")
MailObj.BodyFormat =  1
MailObj.MailFormat = 0
MailObj.Send EmailFromAddress, EmailToAddress, Subject, strComments, File

Response.Write "Thank You, Your Message Has Been Sent"

%>