SunQuest
           Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 9th, 2002, 02:01 AM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 7
convert ASP mailer to PHP?

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 (I was going to paste the ASP Code here but it was 2600 char too long). I have only just started to play with coding so I am very much a newbie. Can anyone help me out?

The company that made the shopping cart gave me this info to help (sic) me on my way.

---------------------------------------------------------------------------

Hello,

well, generally this is a little bit complicated. You cannot use the ASP script, since ASP is only supported by Windows machines using IIS-WebServer-Software.
But I can give you a few more details from what I know about the email service:

The parameters send to the script are the following, all send via a form post, means you can access the values in the same way as you¹d access values from a simple HTML form:

Code:
Interface Configuration		
Name	Type	Description
SiteDirectory	String	Contains the path and the protocol of your store ( e.g: http://www.myshop.com/docs/ )
IsDialogue	String	„true“ if the request comes from the dialogue page, "false" if it is an order.

Interface Recipient		
Name	Type	Description
SenderName	String	Recipient (Name)
To	String	Recipient ( Emailaddress )
From	String	ShopProvider (EmailAddress)
Subject	String	Subjectline

Interface Content ( isDialogue = „true“ )		
Name	Type	Description
Message	String	Your customers dialogue message

Interface Content ( isDialogue = „false“ )		
Name	Type	Description
Message	String	Orderdata ( ShoppingCart etc. )
HeaderUser	String	Headermessage for your customer
HeaderProvider	String	Headermessage for the shop provider
FooterUser	String	Footermessage for Customer
FooterProvider	String	Footermessage for the shop provider
Prolog	String	Introduction (Text)
BillToData	String	Billing Address
ShipToData	String	ShippingAddress
DeliveryMethodData	String	Deliverymethod details
PaymentMethodDate	String	Paymentmethod details

Last edited by direwolf : March 9th, 2002 at 04:59 AM.

Reply With Quote
  #2  
Old March 12th, 2002, 07:02 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
It is not very difficult to convert the asp mailer to php.i'll show you a small exmple how you can do it easily.

test.asp

PHP Code:
<%
    
set mailObj=server.createobject("SMTPsvg.Mailer")
    
mailObj.FromName="fromemailaddress"
    
mailObj.FromAddress="fromemailaddress"
    
mailObj.Subject="subject here"
    
mailObj.BodyText="Message goes here"
    
mailObj.AddRecipient "recipienth email here"
    
mailObj.SendMail
    response
.write("Mail Sent Successfully")
%> 


The same asp code you can convert to php using mail() function.

test.php
PHP Code:
<?
   $to
="recipienth email here"
   
$subject="subject here"
   
$msg="Message goes here"
   
mail($to,$subject,$msg,"Reply-to:fromemailaddress\nFrom:fromemailaddress\n");

  print 
"Mail Sent Successfully";
?>


i hope you understand what i'm trying to explain.

Good Luck!
__________________
SR -
webshiju.com
www.lizratechnologies.com

"The fear of the LORD is the beginning of knowledge..."

Last edited by Shiju Rajan : March 12th, 2002 at 07:04 AM.

Reply With Quote
  #3  
Old March 12th, 2002, 07:21 AM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 7
Ahhh I hate it when someone makes it look so easy.



Yes I can understand your example as I can compare the two. But when I look at the code of the asp mailer, my head hurts. I am trying hard to pick stuff up and when I think I have something worked out it all turns to poo.

Here is a snippet from the code to see what I mean.

Edit: Removed old code

Last edited by direwolf : March 19th, 2002 at 05:44 PM.

Reply With Quote
  #4  
Old March 13th, 2002, 07:47 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
You may convert it easily as i said earlier.
here is the sample code from your code snippet.try to convert all the code like that.



PHP Code:
<?
// Global Variables
// ============================


    // stores, if the procedure should be
    // continued after an error occured.
    // this variable is neccessary in certain
    // subroutines.
    
    
    // continue is being initialised as true.
    
    
$continue =true;
    



    
// stores the result of a procedure, for
    // example if the email has been sent
    // correctly.
    
    // 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
    
    //$isIE = InStr(Request.ServerVariables("HTTP_USER-AGENT"),"MSIE") > 0
    /* find out an appropriate function equalent to above Instr()
       you can see this in php online manual
    */

    // 1. Step: Read existing data
    // ====================================
    // Configuration
    
$strSiteDirectory    $SiteDirectory;
    
// Convert isDialogue into a cariable of type bool ( true/false )
    
$boolIsDialogue        $IsDialogue;


    
// Recipient
    
    
$strSenderName        $SenderName;
    
$strTo                $To;
    
$strFrom            $From;
    
$strSubject            $Subject;

        
// 2. Step: Define Workflow
// ===========================
// Check whether the message is an
// order or a contact request.

        // Contact Request
    
if ($boolIsDialogue) {
        
// 3. Step (a): Read existing data 
        // Read the customers contact request
    
            
            
$strMessage        $Message;

        
        
        
// 4. Step (a) ; Send email
        // Send the contact request by email using
        // the Send_ContactRequest method ( see further down )
            
            
if ($continue) {
                
Send_ContactRequest();
            }
            

    
// Order

        
}else{
        
// 3. Step (b): Read existing data
        // Read the customers order request
        
            
$strMessage                $Message;
            
$strHeaderUser            $HeaderUser;
            
$strHeaderProvider        $HeaderProvider;
            
$strFooterUser            $FooterUser;
            
$strFooterProvider        $FooterProvider;
            
$strProlog                $Prolog;
            
$strBillToData            $BillToData;
            
$strShipToData            $ShipToData;
            
$strDeliveryMethodData    $DeliveryMethodData;
            
$strPaymentMethodData    $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) {
           
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) {
           
Send_OrderToCustomer();
        }
    
}
?>


post your question here, if you are facing any problem to convert.

Reply With Quote
  #5  
Old March 13th, 2002, 07:59 AM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 7
Thank you Shiju Rajan.

I will now spend a few days trying to work the rest of it out from what you have given me so far.

Thank you for your offer to answer more questions from me (I think I may need it )


now the fun begins.


Reply With Quote
  #6  
Old March 15th, 2002, 07:37 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
<<
Thank you for your offer to answer more questions from me (I think I may need it )
now the fun begins.
>>

yea, i know you will make it.

Reply With Quote
  #7  
Old March 15th, 2002, 08:11 AM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 7
Ok, I have given the next snippet a go myself. I must say some of the code is still confusing. I have a basic understanding of pesudo code and "if-then-else" statements and such - but this stuff blows my mind!!

If you could cast your eye over what I have done and point out any errors (I know there will be heaps) that would be great.

Thanks

Edit: Removed old code

Last edited by direwolf : March 19th, 2002 at 05:43 PM.

Reply With Quote
  #8  
Old March 15th, 2002, 11:33 PM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 7
This is the final part I have converted:

Edit: removed old code

Last edited by direwolf : March 19th, 2002 at 05:41 PM.

Reply With Quote
  #9  
Old March 15th, 2002, 11:45 PM
direwolf's Avatar
direwolf direwolf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Australia
Posts: 39 direwolf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 32 m 30 sec
Reputation Power: 7
Ok, I tested the script and it didn't get very far.



Parse error: parse error in /var/www/mail/mailer.php on line 130

which is this line:

Code:
// Define Variables
	// 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.
	
	$isFileProtocol = $siteDirectory,"file:" > 0

Reply With Quote
  #10  
Old March 18th, 2002, 09:46 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
i think someone who is experienced in programming should help you this work going.any way i have just edited your script a bit.you need to edit further for running this script going.


PHP Code:
<?php
// 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
    // 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.
    
    
    
     
$isFileProtocol $siteDirectory;

    
    
// Case 1: No error occured, or the process hasn't been cancelled.
    
if ($result == 0) || ($continue == true) {
        
// for contact requests
        
if ($boolIsDialogue) {
            
// 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 (!($isIE)) && ($isFileProtocol) {
                  
header("Location:$strRedirectTo");
            
// else
             
}else{
                echo 
"<hmtl><body>";
                echo 
"<script>";
                echo 
"location.href = '" .$strSiteDirectory.$strRedirectTo."';";
                echo 
"</script>";
                echo 
"</body></html>";
              }
             
// 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 (!($isIE)) && ($isFileProtocol) {
                
header("Location:success.htm");
            
// else
            
}else{
                
// Page for success message
                
$strRedirectTo "pchase_success.htm";
                echo 
"<hmtl><body>";
                echo 
"<script>";
                echo 
"location.href = '".$strSiteDirectory.$strRedirectTo."';";
                echo 
"</script>";
                echo 
"</body></html>";
            }
         }
         
// Case 2: An error occurred, or the process was cancelled at some stage.
         
       
}else{

        
// for contact requests
        
if ($boolIsDialogue) {
            
// 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 (!$isIE) && ($isFileProtocol) {
                
header("Location:$strRedirectTo);
            // else
            }else{
                echo "
<hmtl><body>";
                echo "
<script>";
                echo "
location.href '".$strSiteDirectory.$strRedirectTo."';";
                echo "
</script>";
                echo "</body></html>";
            }
        // 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 (!$isIE) && ($isFileProtocol) {
                header("Location:error.htm");
            // else
            }else{
                // Page for error message
                $strRedirectTo = "pchase_error.htm"
                echo "<hmtl><body>";
                echo "<script>";
                echo "location.href = '".$strSiteDirectory.$strRedirectTo."';";
                echo "</script>";
                echo "</body></html>";
            }
        }
    }

    // Subroutines
// ===============

// Send_ContactRequest
//     this routine sends a contact request as an email
function Send_ContactRequest(){
     $To=$strTo;
    $Subject=$strSubject;
    $Body=$strMessage;

     mail($To,$Subject,$Body);
     //send the mail
}

// Send_OrderToProvider
//     This method sends an order as an email to the provider
function Send_OrderToProvider(){

      $To        = $strTo
      $Subject    = $strSubject
     
       //Generate Message
       //because the email consists of several parts,
       //these parts have to be put together here.
      $strEmailContent = $strProlog;
      $strEmailContent .=$strHeaderProvider;
      $strEmailContent .=$strBillToData;
      $strEmailContent .=$strShipToData;
      $strEmailContent .=$strDeliveryMethodData;
      $strEmailContent .=$strPaymentMethodData;
      $strEmailContent .=$strMessage;
      $strEmailContent .=$strFooterProvider;
      $Body=$strEmailContent;

      mail($To,$Subject,$Body);
     //send the mail

}


// Send_OrderToCustomer
function Send_OrderToCustomer()
    $To= $strFrom;
    // Add Subject and Message
    $Subject=$strSubject;
    // Generate Message
    //     because the email consists of several parts,
    //     these parts have to be put together here.
    $strEmailContent = $strProlog
    $strEmailContent .=$strHeaderUser;
    $strEmailContent .=$strBillToData;
    $strEmailContent .=$strShipToData;
    $strEmailContent .=$strDeliveryMethodData;
    $strEmailContent .=$strPaymentMethodData;
    $strEmailContent .=$strMessage;
    $strEmailContent .=$strFooterUser;

    $Body=$strEmailContent;
    mail($To,$Subject,$Body);
   //send the mail
}    

// =============================================================================
// =============================================================================
// =============================================================================

// 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){

  switch ($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&nbs