CDO error on invalid email

I am running into a problem with my contact form that I send the data into my system whether I use CDO or CDONTS.
I need to populate the FROM email address to be based off the email address the user fills out in the form.
If the user mistypes like adds a space for some reason it passes my email validation from the client end, but it errors on the server end and the user gets a 500 error
Is there a way to catch the error and if the email is invalid to send it with a different FROM email address?
rivkamakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You can't rely on client side validation and always, always, always validate serverside.  You should also have error trapping.  What does your code look like.

<%
email_to=""
if request.form("email")<>"" then
    email_to=request.form("email"
end if
if email_to<>"" then ' send
    ' sending script via cdo
    else
    ' send back some error data
end if

%>

Open in new window

What is the error checking you are doing on the client side?

Make sure to turn on sending errors to the browser for testing so you can get beyond the 500 error or add this at the top of your script

Err.Clear
On Error Resume Next

Open in new window


then at the bottom
if Err.Number <> 0 Then
    Response.Write ("ERROR: "&Err.Number&": "&Err.Description)
end if

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.