Link to home
Start Free TrialLog in
Avatar of isaacr25
isaacr25

asked on

Script conversion from php to asp

I have an email script written in php, and I need it converted to asp. Please help. Thanks.

<?php


// get posted data into local variables
$EmailFrom = "removed";
$EmailTo = "removed";
$Subject = "removed";
$Name = Trim(stripslashes($_POST['Name']));
$Phone = Trim(stripslashes($_POST['Phone']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
ASKER CERTIFIED SOLUTION
Avatar of Wikkard
Wikkard
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of isaacr25
isaacr25

ASKER

I saved the code as contact.asp, and changed the form action to contact.asp. When I click the submit button, I get a HTTP 500 Internal Server Error, with the domain name plus contact.asp in the address bar. Here is the form code:

<form action="contact.asp" id="form" style="margin:0; padding:0" method="post">
                                                  <div align="center">
                                                    <input name="Name" type="text"  class="w" id="Name" style="width:210px; height:25px;  " value=" &nbsp;your name"  >
                                                    <br>
                                                    <input name="Email" type="text"  class="w" id="Email" style="width:210px; height:25px; " value=" &nbsp;e-mail" >
                                                    <br>
                                                    <input name="Phone" type="text"  class="w" id="Phone" style="width:210px; height:25px; " value=" &nbsp;phone" >
                                                    <br>
                                                    <textarea name="Message"  cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> &nbsp;message</textarea>
                                                  </div>
                                                  <div style="margin:12 15 0 50px;"><input name="clear" type="image" id="clear" style=" border-style:none  " src="images/6_k1.gif" onClick="this.form.reset(); return false;"><input name="submit"  type="image" id="submit" style="border-style:none; margin-left:16px "  src="images/6_k2.gif" >
                                                  </div>
</form>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When I click the Submit button, I get the same results... a blank page with an HTTP 500 Internal Server Error. No error messages are displayed.

ASP CODE:
after <%
response.write now
response.flush


<%@language=vbscript%>
<%
function stripslashes(thedata)
      tmp = replace(thedata,"/","")
      tmp = replace(tmp, "\","")
      stripslashes= tmp 'return the result
end function

'trim is built in vbs function

on error resume next 'might want to comment this line when testing

emailfrom = "removed"
emailto = "removed"
subject = trim(stripslashes(request.form("name")))
phone = trim(stripslashes(request.form("phone")))
email =trim(stripslashes(request.form("email")))
message = trim(stripslashes(request.form("message")))

validationok = true

'validate the above variable
'validationok = false if any errors

if NOT validationOK then
      body = body & "Name: " & name " & vbcrlf
      body = body & "Phone: " & phone & vbcrlf
      body = body & "Email: " & email & vbcrlf
      body = body & "Message: " & message & vbcrlf
end if


'sending email depends on the server and asp components you have available
'easiest way is to use CDONTS
Set myCDONTSMail = CreateObject("CDONTS.NewMail")
myCDONTSMail.Send emailFrom,emailTo,subject,Body

         Set myCDONTSMail  = Nothing


'err is build in error object
if err then
      reponse.redirect("error.htm")
else
      resonse.write "Email Sent"
end if
%>
SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Friendly HTTP errors is already checked. I don't have my own server... I'm using a host provider. I know that the compatibility is with ASP 2.0.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wikkard,
     I did turn off HTTP Friendly errors and tried again, after removing the extra ". This is what was returned:

Microsoft VBScript compilation error '800a0400'

Expected statement

/contact.asp, line 6

<%@language=vbscript
^
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wikkard,
    No code is posted. Thanks.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok Wikkard,
    Now here is the error I'm receiving.

Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object: 'CDOSYS.NewMail'
/contact.asp, line 37
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another error:

ADODB.Fields error '800a0bb9'

Unknown runtime error

/contact.asp, line 46
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Web host is crystaltech.com
Opened in DreamWeaver, line 46 is:

.Item(cdoSendUsingMethod) = 2
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have no idea how to add the field variables/values etc to this script. Is there no easy way to get this done, such as here?

http://www.asptutorial.info/script/formtomail/
Ok,
     I found and used this script, and it works fine: http://www.codefixer.com/tutorials/sample_form_email_script.asp.

My only questions is how do I redirect to a different page upon successful transmission?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What if I need the page to show in a container named "cont"?

When I try
response.redirect("sent.html", "cont")  I get this error:

Microsoft VBScript compilation error '800a0414'

Cannot use parentheses when calling a Sub

/contact.asp, line 37

response.redirect("sent.html", "cont")
--------------------------------------^
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm glad we could help.  However I noticed the B grade.  Did you still need help with this?  If so let us know.

With all of the answers provided and the complete way in which they were provided I don't really understand how you award the B grade.  If it was a mistake or if you have a question about grading then let me know.  I can help you fix it or answer your questions.

It is nice to have a chance to earn the A or at least know why it wasn't.  In this case the answers seem complete enough that I believe it was.

Thanks for the fun question.  Let us know about the grade.

b0lsc0tt
EE Zone Advisor