Hello, I have a shopping cart website that has been set up to send form information to an asp mailer via form post.
the asp mailer is based on another server and I want to have it all on my own Linux apache server. So I need to set up a php form mailer. The only problem is I don't really know where to start. The company sent me the example asp code (below). I have only just started to play with coding so I am very much a newbie. Can anyone help me out?
<%
' Global Variables
' ============================
' stores, if the procedure should be
' continued after an error occured.
' this variable is neccessary in certain
' subroutines.
dim continue
' continue is being initialised as true.
continue = true
' stores the result of a procedure, for
' example if the email has been sent
' correctly.
dim result
' result is being initialised with 0.
' 0 indicates that no error occured yet.
' a value other than 0 indicates an error.
result = 0
' stores if the client is using MSIE
dim isIE
isIE = InStr(Request.ServerVariables("HTTP_USER-AGENT"),"MSIE") > 0
' 1. Step: Read existing data
' ====================================
' Configuration
dim strSiteDirectory, boolIsDialogue
strSiteDirectory = Request.Form("SiteDirectory")
' Convert isDialogue into a cariable of type bool ( true/false )
boolIsDialogue = CBool(Request.Form("IsDialogue"))
' Recipient
dim strSenderName, strTo, strFrom, strSubject
strSenderName = Request.Form("SenderName")
strTo = Request.Form("To")
strFrom = Request.Form("From")
strSubject = Request.Form("Subject")
' 2. Step: Define Workflow
' ===========================
' Check whether the message is an
' order or a contact request.
dim strMessage ' The contact request, or the product data is being stored here
' Contact Request
if boolIsDialogue then
' 3. Step (a): Read existing data
' Read the customers contact request
strMessage = Request.Form("Message")
' 4. Step (a) ; Send email
' Send the contact request by email using
' the Send_ContactRequest method ( see further down )
if continue then Send_ContactRequest
' Order
else
' 3. Step (b): Read existing data
' Read the customers order request
dim strHeaderUser, strHeaderProvider
dim strFooterUser, strFooterProvider
dim strProlog
dim strBillToData, strShipToData
dim strDeliveryMethodData, strPaymentMethodData
strMessage = Request.Form("Message")
strHeaderUser = Request.Form("HeaderUser")
strHeaderProvider = Request.Form("HeaderProvider")
strFooterUser = Request.Form("FooterUser")
strFooterProvider = Request.Form("FooterProvider")
strProlog = Request.Form("Prolog")
strBillToData = Request.Form("BillToData")
strShipToData = Request.Form("ShipToData")
strDeliveryMethodData = Request.Form("DeliveryMethodData")
strPaymentMethodData = Request.Form("PaymentMethodData")
' 4. Step (b) [1]: Send email to store provider
' Send the order request to the store provider
' using the Send_OrderToProvider method ( see further down )
if continue then Send_OrderToProvider()
' 4. Step (b) [2]: Send email to customer
' Send the order request to the customer
' using the Send_OrderToCustomer method ( see further down )
If continue then Send_OrderToCustomer()
end if
' 6.Schritt: Finalize
' =================
' Here we will decide about the site that will be displayed to
' the customer next. We also have to pay attention to the fact
' that an error might have occured during the process.
' Define Variables
dim strRedirectTo ' Name of the page that the user is being redirected to
' Stores if the request has been made from a physical directory
' e.g. a hard disk or a cd-rom.
' in this case we have to pay special attention to Netscape
' customers, coz Netscape doesn't allow you to redirect the
' browser to a local file.
dim isFileProtocol
isFileProtocol = InStr(siteDirectory,"file:") > 0
' Case 1: No error occured, or the process hasn't been cancelled.
if result = 0 Or continue = true then
' for contact requests
if boolIsDialogue then
' page for success message
strRedirectTo = "dialogue_success.htm"
' if the order has been made using netscape and from a local
' directory ( harddisk, or CD-Rom ) then redirect the user
' to a page stored on this webserver.
if not(isIE) and isFileProtocol then
Response.Redirect(strRedirectTo)
' else
else
Response.Write("<hmtl><body>")
Response.Write("<script>")
Response.Write("location.href = '" & strSiteDirectory & strRedirectTo & "';")
Response.Write("</script>")
Response.Write("</body>")
end if
' for orders
else
' if the order has been made using netscape and from a local
' directory ( harddisk, or CD-Rom ) then redirect the user
' to a page stored on this webserver.
if not(isIE) and isFileProtocol then
Response.Redirect("success.htm")
' else
else
' Page for success message
strRedirectTo = "pchase_success.htm"
Response.Write("<hmtl><body>")
Response.Write("<script>")
Response.Write("location.href = '" & strSiteDirectory & strRedirectTo & "';")
Response.Write("</script>")
Response.Write("</body>")
end if
end if
' Case 2: An error occurred, or the process was cancelled at some stage.
else
' for contact requests
if boolIsDialogue then
' Page for error message
strRedirectTo = "dialogue_error.htm"
' if the order has been made using netscape and from a local
' directory ( harddisk, or CD-Rom ) then redirect the user
' to a page stored on this webserver.
if not(isIE) and isFileProtocol then
Response.Redirect(strRedirectTo)
' else
else
Response.Write("<hmtl><body>")
Response.Write("<script>")
Response.Write("location.href = '" & strSiteDirectory & strRedirectTo & "';")
Response.Write("</script>")
Response.Write("</body>")
end if
' for orders
else
' if the order has been made using netscape and from a local
' directory ( harddisk, or CD-Rom ) then redirect the user
' to a page stored on this webserver.
if not(isIE) and isFileProtocol then
Response.Redirect("error.htm")
' else
else
' Page for error message
strRedirectTo = "pchase_error.htm"
Response.Write("<hmtl><body>")
Response.Write("<script>")
Response.Write("location.href = '" & strSiteDirectory & strRedirectTo & "';")
Response.Write("</script>")
Response.Write("</body>")
end if
end if
end if
' =============================================================================
' =============================================================================
' =============================================================================
' Subroutines
' ===============
' Send_ContactRequest
' this routine sends a contact request as an email
function Send_ContactRequest()
dim objCDOMail
On Error Resume Next
' initialise the email component of MS IIS
set objCDOMail = Server.CreateObject("CDONTS.NewMail")
if err <> 0 then
CallError(1) ' ?CDO-Email component can't be intialised
' exit function if continue is false ( critical error )
If not continue then Exit Function
end if
' Add Recipient
objCDOMail.To = strTo
' Add Subject and Message
objCDOMail.Subject = strSubject
objCDOMail.Body = strMessage
' Send Email
objCDOMail.send(strFrom)
if err <> 0 then
CallError(2) ' ?Email can't be sent
' exit function if continue is false ( critical error )
If not continue then Exit Function
end if
' Remove CDO-Email component from memory
set objCDOMail = nothing
end function
' Send_OrderToProvider
' This method sends an order as an email to the provider
function Send_OrderToProvider()
dim objCDOMail
dim strEmailContent
' initialise the email component of MS IIS
set objCDOMail = Server.CreateObject("CDONTS.NewMail")
if err <> 0 then
CallError(3) ' ?CDO-Email component can't be intialised
' exit function if continue is false ( critical error )
If not continue then Exit Function
end if
' Add Recipient
objCDOMail.To = strTo
' Add Subject and Message
objCDOMail.Subject = strSubject
' Generate Message
' because the email consists of several parts,
' these parts have to be put together here.
strEmailContent = strProlog
strEmailContent = strEmailContent & strHeaderProvider
strEmailContent = strEmailContent & strBillToData
strEmailContent = strEmailContent & strShipToData
strEmailContent = strEmailContent & strDeliveryMethodData
strEmailContent = strEmailContent & strPaymentMethodData
strEmailContent = strEmailContent & strMessage
strEmailContent = strEmailContent & strFooterProvider
objCDOMail.Body = strEmailContent
' send email
objCDOMail.send(strFrom)
if err <> 0 then
CallError(4) ' ?Email can't be sent
' exit function if continue is false ( critical error )
If not continue then Exit Function
end if
' Remove CDO-Email component from memory
set objCDOMail = nothing
end function
' Send_OrderToCustomer
' Diese Funktion versendet eine Email als Bestellung
' an den Kunden
function Send_OrderToCustomer()
dim objCDOMail
dim strEmailContent
' initialise the email component of MS IIS
set objCDOMail = Server.CreateObject("CDONTS.NewMail")
if err <> 0 then
CallError(5) ' ?CDO-Email component can't be intialised
' exit function if continue is false ( critical error )
If not continue then Exit Function
end if
' Add Recipient
' Attention: Here, the the recipient is the sender
' of the actual order. Therefore the variables
' 'strTo' and 'strFrom' have to be switched
objCDOMail.To = strFrom
' Add Subject and Message
objCDOMail.Subject = strSubject
' Generate Message
' because the email consists of several parts,
' these parts have to be put together here.
strEmailContent = strProlog
strEmailContent = strEmailContent & strHeaderUser
strEmailContent = strEmailContent & strBillToData
strEmailContent = strEmailContent & strShipToData
strEmailContent = strEmailContent & strDeliveryMethodData
strEmailContent = strEmailContent & strPaymentMethodData
strEmailContent = strEmailContent & strMessage
strEmailContent = strEmailContent & strFooterUser
objCDOMail.Body = strEmailContent
' send email
objCDOMail.send(strTo)
if err <> 0 then
CallError(6) ' ?Email can't be sent
' exit function if continue is false ( critical error )
If not continue then Exit Function
end if
' Remove CDO-Email component from memory
set objCDOMail = nothing
end function
' =============================================================================
' =============================================================================
' =============================================================================
' Errorhandling
' ================
' Here we will check possible errors. Depending on the
' kind of error, we can decide whether we want to continue
' or cancel the order processing.
function CallError(intErrorCode)
select case intErrorCode
case 1
' The CDO-Email component couldn't be initialised
' during the processing of a contact request.
' The process is being cancelled
continue = false
' store error in the result variable
result = result + 32
case 2
' An error occurred during the process of a contact
' request.
' The process is being cancelled
continue = false
' store error in the result variable
result = result + 16
case 3
' The CDO-Email component couldn't be initialised
' during the processing of an order.
' The process is being cancelled
continue = false
' store error in the result variable
result = result + 8
case 4
' An error occured during the processing of an order.
' No email could be sent to the store provider.
' The process is being cancelled
continue = false
' store error in the result variable
result = result + 4
case 5
' The CDO-Email component couldn't be initialised
' during the processing of an order.
' The process is being cancelled
continue = false
' store error in the result variable
result = result + 2
case 6
' An error occured during the processing of an order.
' No email could be sent to the customer.
' The process is being continued
continue = false
' store error in the result variable
result = result + 1
end select
end Function
%>