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\ ">";
}
?>
<?php
// get posted data into local variables
$EmailFrom = "removed";
$EmailTo = "removed";
$Subject = "removed";
$Name = Trim(stripslashes($_POST['
$Phone = Trim(stripslashes($_POST['
$Email = Trim(stripslashes($_POST['
$Message = Trim(stripslashes($_POST['
// 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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("phon e")))
email =trim(stripslashes(request .form("ema il")))
message = trim(stripslashes(request. form("mess age")))
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.NewMa il")
myCDONTSMail.Send emailFrom,emailTo,subject, Body
Set myCDONTSMail = Nothing
'err is build in error object
if err then
reponse.redirect("error.ht m")
else
resonse.write "Email Sent"
end if
%>
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.
phone = trim(stripslashes(request.
email =trim(stripslashes(request
message = trim(stripslashes(request.
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.NewMa
myCDONTSMail.Send emailFrom,emailTo,subject,
Set myCDONTSMail = Nothing
'err is build in error object
if err then
reponse.redirect("error.ht
else
resonse.write "Email Sent"
end if
%>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
^
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wikkard,
No code is posted. Thanks.
No code is posted. Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Another error:
ADODB.Fields error '800a0bb9'
Unknown runtime error
/contact.asp, line 46
ADODB.Fields error '800a0bb9'
Unknown runtime error
/contact.asp, line 46
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Web host is crystaltech.com
ASKER
Opened in DreamWeaver, line 46 is:
.Item(cdoSendUsingMethod) = 2
.Item(cdoSendUsingMethod) = 2
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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/
http://www.asptutorial.info/script/formtomail/
ASKER
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What if I need the page to show in a container named "cont"?
When I try
response.redirect("sent.ht ml", "cont") I get this error:
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/contact.asp, line 37
response.redirect("sent.ht ml", "cont")
-------------------------- ---------- --^
When I try
response.redirect("sent.ht
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/contact.asp, line 37
response.redirect("sent.ht
--------------------------
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
<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=" your name" >
<br>
<input name="Email" type="text" class="w" id="Email" style="width:210px; height:25px; " value=" e-mail" >
<br>
<input name="Phone" type="text" class="w" id="Phone" style="width:210px; height:25px; " value=" phone" >
<br>
<textarea name="Message" cols="35" rows="35" class="w" id="Message" style="width:210px; height:90px; overflow:hidden "> 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()
</div>
</form>