View Full Version : formatted email
worm
July 23rd, 2003, 05:28 PM
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
Digitalosophy
July 23rd, 2003, 05:31 PM
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
worm
July 23rd, 2003, 05:35 PM
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
Digitalosophy
July 23rd, 2003, 05:54 PM
lol no problem, but first, what are you using, php or asp?
worm
July 23rd, 2003, 05:59 PM
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
Digitalosophy
July 23rd, 2003, 06:08 PM
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
worm
July 23rd, 2003, 07:30 PM
okay, i have asp support so shoot away!
Digitalosophy
July 23rd, 2003, 07:52 PM
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
worm
July 23rd, 2003, 08:16 PM
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
Digitalosophy
July 23rd, 2003, 08:42 PM
no problem, did you figure it all out?
worm
July 23rd, 2003, 08:48 PM
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?
Digitalosophy
July 23rd, 2003, 08:58 PM
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
worm
July 23rd, 2003, 09:59 PM
well the test thing worked so that must mean im on the right track, right
:-)
Digitalosophy
July 23rd, 2003, 10:17 PM
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
worm
July 24th, 2003, 02:00 PM
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 [b]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
Digitalosophy
July 24th, 2003, 02:57 PM
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 :)
worm
July 24th, 2003, 04:11 PM
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!
worm
July 24th, 2003, 05:43 PM
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 webmaster@asp101.com."
' 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
%>
worm
July 24th, 2003, 06:51 PM
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
Digitalosophy
July 24th, 2003, 08:57 PM
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"
%>
worm
July 24th, 2003, 09:04 PM
when i go to the test.asp page, i c the folllowing
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/test/test.asp, line 21
800401f3
Digitalosophy
July 24th, 2003, 09:47 PM
Why do I get a Server.CreateObject Failed When trying to use CDONTS?
Because you do not have the SMTL service installed on the server. In order to use CDONTS the SMTP service must be installed on the web server. If you are hosted with someone contact your ISP to see what mail component you have avaialble to you.
your mail server is not configured right
Digitalosophy
July 24th, 2003, 09:52 PM
see if your server supports php
worm
July 25th, 2003, 12:22 PM
how, is there a test to do this?
Digitalosophy
July 25th, 2003, 01:41 PM
<?php
phpinfo();
?>
create a file with that code, and run it
worm
July 25th, 2003, 03:54 PM
did that and when i requested the page, i got a download file prompt
Digitalosophy
July 25th, 2003, 06:15 PM
huh? are you running it off your web server?
worm
July 25th, 2003, 06:21 PM
edit:yep i did.
for the record i've confirmed that i do in fact have asp on my server and not php
i also have a folder named cgi-bin which they instructed me to put all my asp pages in.
will this make a difference in the whole process?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.