We help IT Professionals succeed at work.
Get Started

Unable to send email from website

Angel02
Angel02 asked
on
515 Views
Last Modified: 2012-08-14
I need to let users send email from our website's contact form. Our website is hosted on myhosting.com. I am using the attached code to send email.
The send() method is failing and returning the error "An error occured. Please contact the webmaster of this site."

Is this because our host server (myhosting.com) is not allowing us to send email or something in the code?
We have our own exchange server. Can I make use of our exchange server to send email while the website resides on myhosting (like using smtp) ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
.style3 {color: #0F5A7A}
.style4 {font-size: 12px}
.style5 {
	font-size: 14px;
	color: #333333;
}
</style>
<script language="javascript">
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
</script>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body>

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="backgr">
              <tr>
              <td>
              <p class="style4"><strong>Thank You ! <br/>
              The email has been sent.</strong></p>
              </td>
              </tr>
          </table>
 </body>
<!-- InstanceEnd -->
<%
Dim name, email, message, NewMailObj
name=request.form("textBoxName")
email=request.form("textBoxEmail")
message=request.form("textBoxMessage")

'create the mail object and send the details
Set NewMailObj=Server.CreateObject("JMail.Message")
NewMailObj.Logging = true
NewMailObj.silent = true
NewMailObj.From = email
NewMailObj.FromName = name
NewMailObj.AddRecipient("myemail@gmail.com")
NewMailObj.AddRecipient("myemail@yahoo.com")
NewMailObj.Subject = "Website Contact Form" 
NewMailObj.Body = message 

'you need to add the following lines FOR the mail to be sent in HTML format
'NewMailObj.BodyFormat = 0 
'NewMailObj.MailFormat = 0 
if not NewMailObj.Send("mail.mydomain.com") then
Response.write "An error occured. Please contact the webmaster of this site."
else
'Close the email object and free up resources 
Set NewMailObj = nothing
Response.write "The email was sent."
end if
%>  </html>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE