sendorder.asp (CDONTS alternative)

windows

Guest
Hi all, this is only my second post so please excuse any ignorance...

I am working on a website that has a shopping cart. The order for the cart is generated using javascript and SQL on as ASP page. No problems yet.

The problem is with sending the order as an email to the company.

The (abbreviated) code is below, the variables: (email, subject, message, order_id, etc..) are all getting assigned values appropriately.

Here's the main code I'm concerned with:


<%@ Language=JScript %>
<%

con = db_connect_ ();
con.Execute (...some SQL...);
rs = con.Execute (...more SQL...);

con = db_connect_ ();
rs.Close ();
con.Close ();

mail = Server.CreateObject ("CDONTS.NewMail");
mail.Subject = "Order #" + order_id + "\n";
mail.From = name + "@seauto.com";
mail.To = "[email protected]";
mail.Cc = email;
mail.Body = mail_body;
mail.Send();
%>

<?php
// Your email address
$email = "[email protected]";
// The subject
$subject = "Enter your subject here";
// The message
$message = "Enter your message here";
mail($email, $subject, $message, "From: $email");
echo "The email has been sent.";
?>

The mail.send() command is just not working.
No errors are produced, but no email is sent. I've researched this a bunch, and it seems windows XP doesn't support the CDONTS mail object. I read you can use 'jmail', but I don't understand how to "register the class" on my server. I would rather use PHP, you can see my attempt at the end of the code segment, but that doesn't work either.

Any suggestion? ...I'm desparate.
All I need to do is send an email with the values of the above-listed variables in the email.

Many thanks,
Cort
MrExcel.comFirst off, why do you have ASP and PHP in the same page???

There's a way in ASP to switch to PHP-style scripting, but you can't just plop <?php in the middle of an ASP - I don't think that will work at all.

On to CDONTS....XP has done away with the use of CDONTS but not sending emails altogether. They simply use a different version of CDONTS now called CDO or CDOSYS.
Here's an example on how to use it .....

<!-- m --><a class="postlink" href="http://www.paulsadowski.com/WSH/cdo.htmI">http://www.paulsadowski.com/WSH/cdo.htmI</a><!-- m --> didn't know you couldn't switch to PHP on the ASP page. As I said.. this is new to me. I only wanted to use that PHP function because I know works, I've used it elsewhere.

I have read about CDOSYS and attempted to use that method.. with no luck. I didn't get my examples from the link you provided, though, so I'll go try that.

Thanks for your help, I need all I can get.
(if you ever need help with Access/Excel, just let me know!)

-CortOkay, I replaced this (which did not produce an error but just didn't do anything):
mail = Server.CreateObject ("CDONTS.NewMail");
mail.Subject = "Order #" + order_id + "\n";
mail.From = name + "@seauto.com";
mail.To = "[email protected]";
mail.Cc = email;
mail.Body = mail_body;
mail.Send();

with this (I tried it with and without the semicolon at the end of each line - both produced the same error listed below):
set objMessage = CreateObject("CDO.Message");
objMessage.Subject = "Example CDO Message";
objMessage.Sender = "[email protected]";
objMessage.To = "[email protected]";
objMessage.TextBody = "This is some sample message text.";
objMessage.Send;

I get the following error. This is the same error I got last time I tried to use CDO.

Microsoft JScript compilation error '800a03ec'
Expected ';'
/send_order.asp, line 118
set objMessage = CreateObject("CDO.Message");
----^

Thanks for any assistance,
CortHave you tried this code in VBScript rather than JScript?

JScript is hard to find good examples for and it's not really my forte.

In JScript, I'm pretty sure you need to identify the object type before you can instantiate a variable.
E.G.

object objMessage = Server.CreateObject("CDO.Message");


....but, I could be wrong. Again, my JScript experience in ASP is limited.Originally posted by Corticus
Okay, I replaced this (which did not produce an error but just didn't do anything):
mail = Server.CreateObject ("CDONTS.NewMail");
mail.Subject = "Order #" + order_id + "\n";
mail.From = name + "@seauto.com";
mail.To = "[email protected]";
mail.Cc = email;
mail.Body = mail_body;
mail.Send();

with this (I tried it with and without the semicolon at the end of each line - both produced the same error listed below):
set objMessage = CreateObject("CDO.Message");
objMessage.Subject = "Example CDO Message";
objMessage.Sender = "[email protected]";
objMessage.To = "[email protected]";
objMessage.TextBody = "This is some sample message text.";
objMessage.Send;

I get the following error. This is the same error I got last time I tried to use CDO.

Microsoft JScript compilation error '800a03ec'
Expected ';'
/send_order.asp, line 118
set objMessage = CreateObject("CDO.Message");
----^

Thanks for any assistance,
Cort

I am not sure this script would work at all ...
"set" keyword is VBScript specific.

Putts, Jscript is the same as VBScript, but it assumes the type even if you do

var x = new String();
x = 1.0f;

it becomes a float not a string like it would in VB.

However the script would work if it was correctly set up

var x = Server.CreateObject("CDO.Message")
x.To = "";
x.Send();


Notice:

var x = Server.CreateObject("CDO.Message")


This creates the component in Process with IUSR_ as the calling user. If you use the it without it becomes out of process and requires more premissions to execute the code.I just wanna point out...Ryan et al..that you can call asp and php on the same page..but they need to be processed by both the asp engine and the php engine.If the server is configured properly....:


<%
'ASP Code
%?>
<?php
//PHP Code
?>


will work fine.I don't do windows administration..so I can't tell you how to set it up.

Edit:

As far as fixing the php script:


<?php
// Your email address
$email = "[email protected]";
// The subject
$subject = "Enter your subject here";
// The message
$message = "Enter your message here";
$headers = '';
$headers .= "From: $email \r\n";
mail($email, $subject, $message, $headers) or die("Could Not Send E-Mail");
echo "The email has been sent.";
?>You don't need to go that far......I'm pretty sure you can program PHP syntax right with ASP by just using some....

<@ Language=PHPScript>

Just like how you can switch to JScript and back. Seems like it'd be less overhead than having the compiler needed to do the PHP and the ASP all checking out every page that loads.

Not sure where to get that language update for ASP, but I'm pretty sure I've heard it exists.Thanks for all the replies!

I think I'm going to experiment with getting the PHP to work. I'll let you know how it goes.

-CortI would like to note that CDO NT requires that the Server executing the script have a SMTP server installed locally.Sorry to jump into the converstation late...but I thought I'd include a simple SMTP email form I whipped up. I was also having difficulty with CDONTs, so I switched to this solution, worked great for the simple application I needed it for...but as afterburn pointed out, I had to have my SMTP services installed and running on my machine


Imports System.Web.Mail

...

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

Dim oMessage As New MailMessage
oMessage.BodyFormat = MailFormat.Html
oMessage.From = Me.TextBoxFrom.Text
oMessage.To = Me.TextBoxTo.Text
oMessage.Body = Me.TextAreaBody.InnerText
oMessage.Subject = Me.TextBoxSubject.Text
oMessage.Cc = Me.TextBoxCc.Text
oMessage.Priority = MailPriority.Normal
oMessage.BodyEncoding = System.Text.Encoding.ASCII

Dim smtpServerName As String = "mail_server_location"
SmtpMail.SmtpServer = smtpServerName
SmtpMail.Send(oMessage)

End SubThat is in ASP.net he looks to be programming in ASP/PHP on Windows.

It also uses the CDO SYS not CDO NT as he is attempting to do.Thanks for additional info all, I appreciate all the help.

I have to sort through this stuff and try everything out, I'll let you know how it goes.
 
Back
Top