Sending Dialog Contents via Email


There are times when the output of a dialog should not go directly to a database. You may want to email the entry, for example. Here is how you would do that, assuming that once again you are starting with our Simple Dialog example.

In the Xbasic functions section of your dialog, insert this function:

FUNCTION sendEmail AS L (address AS C, subject as C, body AS C )
  dim pm as P
  dim ps as P
  sendEmail= .F.
  IF (email_smtp_open(ps, "", 25, "[email protected]","password")) = address
		pm.from = ""
		pm.from_alias = "My Email Alias"
		pm.subject = subject
		pm.message = body
		sendEmail = email_smtp_send(pm, ps)

You will need to edit the function for your server, which is why we have inserted the debug statement for you. In the afterDialogValidate event, insert the following code:

function afterDialogValidate as v (e as p)
'... comments omitted here ...
dim address as C = "[email protected]"
dim subject as C = "Captured Combatant"
dim body as C
body = "NAME: " + e.dataSubmitted.NAME + crlf()
body = body + "RANK: " + e.dataSubmitted.RANK + crlf()
body = body + "SERIALNR " + e.dataSubmitted.SERIALNR + crlf()
if sendEmail(address,subject,body)
	e.javascript="alert('Submitted: "+e.dataSubmitted.NAME + ", " + e.dataSubmitted.RANK
	e.javascript=e.javascript + ", " + e.dataSubmitted.SERIALNR + ", "
end if
end function

You will obviously have to edit the address to be the intended, valid email.