Solved

CDOSYS not sending email - code correct?!?!?

Posted on 2007-04-04
8
284 Views
Last Modified: 2010-04-16
I have setup a form which I want sending using CDOSYS. It all appears to be working fine and the confirmation page shows no errors - however no email is sent and I do not know why! The code appears to be all correct!

This is the code:

[code]

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
'First lets Dim all the variables we need - this is a comment
Dim MyName
Dim MyAddress
Dim MyPostcode
Dim MyTelephone
Dim MyEmail
Dim MyMessage

'Now lets get some values for the variables from the form
MyName = Request.Form("Name")
MyAddress = Request.Form("Address")
MyPostcode = Request.Form("Postcode")
MyTelephone = Request.Form("Telephone")
MyEmail = Request.Form("Email")
MyMessage = Request.Form("Message")

'Now lets build the body of the email from the data in the form
MyBody = "Name: "& MyName & vbcrlf
MyBody = MyBody & "Address: "& MyAddress & vbcrlf
MyBody = MyBody & "Postcode: "& MyPostcode & vbcrlf
MyBody = MyBody & "Telephone: "& MyTelephone & vbcrlf & vbcrlf
MyBody = MyBody & "Email: "& MyEmail & vbcrlf
MyBody = MyBody & "Message: "& MyMessage & vbcrlf

'Now lets put the variables and other information we need into the mailing script
Set MyMail = CreateObject("CDO.Message")
MyMail.From = "fama@fama.co.uk"
MyMail.To = "paul.worsnop@tesco.net"
MyMail.Subject = "Website Enquiry from Fama.co.uk"
MyMail.TextBody = MyBody
MyMail.Send
Set MyMail= nothing
Response.Write("Your e-mail has been sent")
%>

[/code]
0
Comment
Question by:dwaarchitects
  • 3
  • 2
8 Comments
 
LVL 19

Expert Comment

by:Rimvis
ID: 18849742
Do you have Simple Mail Transport Protocol (SMTP) service installed on your WEB server? Is it running?
0
 

Author Comment

by:dwaarchitects
ID: 18849774
It is stored externally on the web hosts servers i dont do it from a web server that I administer myself.
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 18849851
a) Maybe you can ask web server administrator to check it?
b) You can send e-mail using specific SMTP server: http://msdn2.microsoft.com/en-us/library/ms527274.aspx
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:dwaarchitects
ID: 18850256
Have emailed them asking if can check things out at their end.
One other thing I would like to have setup but am unsure as to how to is I would like the user who fills the form in to recieve a confirmation email stating we have recieved their enquiry - is it a simple addition to the current code to do this?!?!
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 125 total points
ID: 18850337
I'm not sure what do you want to achieve. As I understand, you current code is sending user message to some fixed address. If you just want to send user a response e-mail right after message is sent, thinks are simple. Just create a function that sends message with supplied parameters, like



<%

Sub SendEmail(sFrom, sTo, sSubject, sBody)
   Set MyMail = CreateObject("CDO.Message")
   MyMail.From = sFrom
   MyMail.To = sTo
   MyMail.Subject = sSubject
   MyMail.TextBody = sBody
   MyMail.Send
   Set MyMail= nothing
End Sub


'First lets Dim all the variables we need - this is a comment
Dim MyName
Dim MyAddress
Dim MyPostcode
Dim MyTelephone
Dim MyEmail
Dim MyMessage

'Now lets get some values for the variables from the form
MyName = Request.Form("Name")
MyAddress = Request.Form("Address")
MyPostcode = Request.Form("Postcode")
MyTelephone = Request.Form("Telephone")
MyEmail = Request.Form("Email")
MyMessage = Request.Form("Message")

'Now lets build the body of the email from the data in the form
MyBody = "Name: "& MyName & vbcrlf
MyBody = MyBody & "Address: "& MyAddress & vbcrlf
MyBody = MyBody & "Postcode: "& MyPostcode & vbcrlf
MyBody = MyBody & "Telephone: "& MyTelephone & vbcrlf & vbcrlf
MyBody = MyBody & "Email: "& MyEmail & vbcrlf
MyBody = MyBody & "Message: "& MyMessage & vbcrlf

'send mail to Paul
SendEmail("fama@fama.co.uk", "paul.worsnop@tesco.net", "Website Enquiry from Fama.co.uk", MyBody)

'send response to user
SendEmail("fama@fama.co.uk", MyEmail , "Response from Fama.co.uk", "Your enquiry has been received")

%>

0
 
LVL 4

Expert Comment

by:IceCode
ID: 18940744
<%
'Send first email

'Now lets get some values for the variables from the form
MyName = Request.Form("Name")
MyAddress = Request.Form("Address")
MyPostcode = Request.Form("Postcode")
MyTelephone = Request.Form("Telephone")
MyEmail = Request.Form("Email")
MyMessage = Request.Form("Message")

'Now lets build the body of the email from the data in the form
MyBody = "Name: "& MyName & vbcrlf
MyBody = MyBody & "Address: "& MyAddress & vbcrlf
MyBody = MyBody & "Postcode: "& MyPostcode & vbcrlf
MyBody = MyBody & "Telephone: "& MyTelephone & vbcrlf & vbcrlf
MyBody = MyBody & "Email: "& MyEmail & vbcrlf
MyBody = MyBody & "Message: "& MyMessage & vbcrlf

'Now lets put the variables and other information we need into the mailing script
Set MyMail = Server.CreateObject("CDO.Message")
Set MyMailConfig = Server.CreateObject("CDO.configuration")
            MyMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xxx.xxx.xxx.xxx"
            MyMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            MyMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            MyMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
            MyMailConfig.Fields.Update
Set MyMail.Configuration = MyMailConfig

MyMail.From = "fama@fama.co.uk"
MyMail.To = "paul.worsnop@tesco.net"
MyMail.Subject = "Website Enquiry from Fama.co.uk"
MyMail.TextBody = MyBody
MyMail.Send
Set MyMail= nothing
Response.Write("Your e-mail has been sent")

'Repeat above to send confimration...  Change to,subject,textbody
%>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Recordset containing single quotes 8 43
Connection to multiple databases 13 25
key press alert 2 32
IIS 7 and executing pages using localhost 16 13
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question