Hello I am a asp newbie trying to send an notification email and update an access database at the same time. My database is being updated but the email portion is not working- the email portion is in php- Can I call it from my asp page and if so how/where:

my php page is contactusprocess.php

My ASP code is:

[<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/InformationRequested2.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_InformationRequested2_STRING
    MM_editCmd.CommandText = "INSERT INTO [Contact Us] (Message, [Bank Name], [First Name], [Last Name], [Phone Number], Email) VALUES (?, ?, ?, ?, ?, ?)" 
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, -1, Request.Form("Message")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 255, Request.Form("Bank Name")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 255, Request.Form("First Name")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, 255, Request.Form("Last Name")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, 255, Request.Form("Phone Number")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 201, 1, -1, Request.Form("Email Address")) ' adLongVarChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

        ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "AOCQuestionSubmitted.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>
<!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/McCormTemplate.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Contact MAi</title>
<!-- InstanceEndEditable -->
<link href="CSS/McCorm.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
    background-color: #F9FAFC;
    background-image: url(Images/Background.jpg);
    background-repeat: repeat-x;
}
-->
</style>
<!-- InstanceBeginEditable name="head" -->
<script src="SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="Wrapper">
  <div id="Logo">
    <div id="LogoText">
      <p class="h1">McCormack &amp; Associates, inc.</p>
      <p class="h3">Bankers Helping Bankers</h3>
      </div>
  <a href="index.asp"><img src="Images/final gif 092010.gif" alt="MAi Logo" width="135" height="90" /></a></div>
  <!-- InstanceBeginEditable name="headerimg" --><img src="Images/bigstock_Planning_2738738.jpg" width="950" height="250" /><!-- InstanceEndEditable -->
  <div id="bodyArea">
    <div id="left">
      <ul id="MenuBar1" class="MenuBarVertical">
        <li><a href="index.asp">Home</a>        </li>
        <li><a href="Services.asp">Services</a></li>
        <li><a href="FeaturedServices.asp">Featured</a>        </li>
        <li><a href="Consultants Auditors.asp" class="MenuBarItemSubmenu">Meet MAi</a>
          <ul>
<li><a href="Consultants Auditors.asp">Consultants</a></li>
<li><a href="Staff.asp">Staff</a></li>
          </ul>
        </li>
<li><a href="Careers.asp">Careers</a></li>
<li><a href="ClientNews.asp">Industry News</a></li>
        <li><a href="ClientNews.asp">Resources</a></li>
        <li><a href="aoc.asp">Auditor on Call</a></li>
<li><a href="" target="_blank">Client Access</a></li>
<li><a href="">Examiner Access</a></li>
<li><a href="Contact Us.asp">Contact Us</a></li>
      </ul>
      <p>&nbsp;</p>
      <p><br />
      </p>
<br />
<br />

    </div>
    <div id="right">
      <div id="middle"><!-- InstanceBeginEditable name="MiddleRegion" -->
        <form action="<%=MM_editAction%>" method="POST" name="form1" id="form1" accept-charset="iso-8859-1">
          <div id="formdiv">
            <p>&nbsp;</p>
            <div id="Contact Form">
              <p class="center">&nbsp;</p>
              <p><span id="sprytextarea1"><span id="sprytextarea2">
                <label>Message
                  <textarea name="Message" cols="40" rows="5" class="contactmessage" id="Message"></textarea>
                  <br />
                  <br />
                  Bank Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input name="Bank Name" type="text" class="alignformfieldwider" id="Bank Name" />
                  <br />
                  <br />
                  First Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input name="First Name" type="text" class="alignformfieldwider" id="First Name" />
                </label>
                <span class="textareaRequiredMsg">A value is required.</span></span><span class="textareaRequiredMsg">A value is required.</span></span></p>
              <p>&nbsp;</p>
              <p>
                <label>Last Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&thinsp;
                  <input name="Last Name" type="text" class="alignformfieldwider" id="Last Name" />
                </label>
              </p>
              <p>&nbsp;</p>
              <p>
                <label>Phone Number&nbsp;&nbsp;&nbsp;&nbsp;&thinsp;
                  <input name="Phone Number" type="text" class="alignformfieldwider" id="Phone Number" />
                </label>
              </p>
              <p>&nbsp;</p>
              <p><span id="sprytextfield1"><span id="sprytextfield2">
                <label>Email Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&thinsp;
                  <input name="Email Address" type="text" class="alignformfieldwider" id="Email Address" />
                </label>
                <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></p>
              <p>&nbsp;</p>
              <p>
                <label><br />
                  <input name="SUBMIT" type="submit" class="pcenter" id="SUBMIT" value="Submit" />
                </label>
                <input type="reset" name="Reset" id="Reset" value="Reset" />
              </p>
            </div>
          </div>
          <input type="hidden" name="MM_insert" value="form1" />
          <input type="hidden" name="hdwuploadfolder" id="hdwuploadfolder" value="Uploads" />
          <input type="hidden" name="hdwtablename" id="hdwtablename" value="Contact Us" />
          <input type="hidden" name="hdwok" id="hdwok" value="AOCQuestionSubmitted.asp" />
          <input type="hidden" name="hdwemail" id="hdwemail" value="info+mccorm.com" />
          <input type="hidden" name="hdwnook" id="hdwnook" value="AOC CONTACT Fail.asp" />
        </form>
      <!-- InstanceEndEditable --></div>
      <div id="rightside"><!-- InstanceBeginEditable name="RightRegion" -->
        <p>&nbsp;</p>
        <p>&nbsp;</p>
<p>&nbsp;</p>
        <p><img src="Images/address.gif" width="275" height="275" align="middle" /><br />
          <br />
        </p>
        <script type="text/javascript">
<!--
var sprytextarea2 = new Spry.Widget.ValidationTextarea("sprytextarea2");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email");
//-->
        </script>
      <!-- InstanceEndEditable --></div>
    </div>
    <!--right close-->
  </div>
  <div id="footer"></div>
  <!--body area close-->




</div><!--end of wrapper-->
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-19621495-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? '' : '') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>
<!-- InstanceEnd --></html>]

I've hit a brick wall trying to figure it out. I really appreciate your help

Dani AI

Generated

Short summary and practical plan (for , building on 's suggestion):

Classic ASP cannot directly execute PHP inside the same file — the server runs one engine per request — so either send mail from ASP (recommended) or have ASP call the existing PHP script over HTTP. The most straightforward, maintainable fix is to convert the PHP mail step into an ASP send using CDO (CDOSYS) and then redirect; CDOSYS is the native mechanism on Windows/IIS for sending mail from Classic ASP. (learn.microsoft.com)

Where to put the mail code (concrete): perform the INSERT first, then send the e-mail, and only after a successful send (or after logging a nonfatal send error) do the Response.Redirect. That ensures the send happens during the same user request and avoids losing errors to the redirect. If keeping the PHP mailer, make a server-side POST from ASP to the PHP URL (do not try to mix PHP tags into the .asp file). (learn.microsoft.com)

If calling the PHP page from ASP, use MSXML ServerXMLHTTP to POST the form fields and check the HTTP status/response text before redirecting. Example pattern:

Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.open "POST", "https://example.com/contactusprocess.php", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
postdata = "Message=" & Server.URLEncode(Request.Form("Message")) & "&Email=" & Server.URLEncode(Request.Form("Email Address"))
http.send postdata
' check http.Status and http.responseText here

Troubleshooting checklist and cautions: confirm the recipient address hidden field is correct (the form shows hdwemail="info+mccorm.com" which looks wrong/obfuscated), verify the server can reach the SMTP host (telnet smtp.example.com 25/587 or use your hosting control panel), add simple error handling around the mail/send call and log Err.Number/Err.Description or the ServerXMLHTTP responseText, and if using an external SMTP provider enable authentication and TLS in the CDOSYS configuration (CDO requires explicit SMTP fields when not using a local pickup directory). (learn.microsoft.com)

Suggested first step: try a tiny standalone ASP page that uses CDO to send a test email (or POSTs to the PHP page) so the DB update is isolated while debugging. Once mail send is verified, integrate it after the MM_editCmd.Execute and before the redirect, and add error logging so failures are visible in logs.

PHP and ASP are two distinctly different programming languages that will not run on the same web page at all.

Thank you- No wonder I'm stumped. Do you have or know where I can get example code of an ASP email notification using CDOSYS?

Sure...

Set ObjSendMail = CreateObject("CDO.Message")   
	ObjSendMail.Configuration.Fields.Item ("") = 2 'Send using SMTP
	ObjSendMail.Configuration.Fields.Item ("") = strMailServer
	ObjSendMail.Configuration.Fields.Item ("") = 25
	ObjSendMail.Configuration.Fields.Item ("") = strHtmlFormat 
	ObjSendMail.Configuration.Fields.Item ("") = 60    
	ObjSendMail.Configuration.Fields.Update	
	ObjSendMail.To = strToEmail
	ObjSendMail.Subject = strSubject
	ObjSendMail.From = strFromEmail
   	ObjSendMail.TextBody = strMessage 
	ObjSendMail.Send
	Set ObjSendMail = Nothing

Thank you so much- Do I post this code into the original asp document and if so where? As you can tell I'm a newbie and I really appreciate it!

Place it wherever (when) you want it send the email. Buy be sure to load the variables somewhere before it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.