Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active July 13, 2022 22:05
Show Gist options
  • Save stevewithington/cc6ea167cfd847426cc5 to your computer and use it in GitHub Desktop.
Save stevewithington/cc6ea167cfd847426cc5 to your computer and use it in GitHub Desktop.
CFMail Test File
<!---
// For GMAIL accounts:
server=smtp.gmail.com
port=465
useSSL=yes
--->
<cfparam name="form.message" default="Test" />
<cfparam name="form.to" default="[email protected]" />
<cfparam name="form.from" default="user@localhost" />
<cfparam name="form.username" default="" />
<cfparam name="form.subject" default="Test Email" />
<cfparam name="form.password" default="" />
<cfparam name="form.server" default="localhost" />
<cfparam name="form.port" default="25" />
<cfparam name="form.useSSL" default="false" />
<cfparam name="form.useTLS" default="true" />
<cfparam name="form.useDefaultSMTP" default="false" />
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CFMail Test</title>
<style type="text/css">
h3,h4 {padding:0 1em;margin:0;}
label {display:block;clear:both; padding:1em 0 0.25em 0; font-weight:bold;}
label.inline {display:inline-block; padding-right: 1em;}
input[type="text"], textarea { width: 300px;}
textarea {height:100px;}
input[type="submit"] { display:block; clear:both; margin:1em 0;}
fieldset {width:400px; float:left; border:none;}
p.alert {padding:0.5em;margin:0 1em;background-color:grey;color:white;}
</style>
</head>
<body>
<cfoutput>
<h3>CFMail Test</h3>
<cfif StructKeyExists(form, 'submit')>
<cfif form.useDefaultSMTP>
<cfmail
to="#form.to#"
from="#form.from#"
replyto="#form.from#"
failto="#form.from#"
subject="#form.subject#"
charset="utf-8">
#form.message#
</cfmail>
<p class="alert alert-info">
E-Mail sent using the default SMTP settings.<br>
Check logs for unspooled messages.
</p>
<cfelse>
<cfmail
to="#form.to#"
from="#form.from#"
replyto="#form.from#"
failto="#form.from#"
username="#form.username#"
subject="#form.subject#"
password="#form.password#"
server="#form.server#"
port="#form.port#"
useSSL="#form.useSSL#"
useTLS="#form.useSSL#"
charset="utf-8">
#form.message#
</cfmail>
<p class="alert alert-info">
E-Mail sent using the form data.<br>
Check logs for unspooled messages.
</p>
</cfif>
<cfdump var="#form#">
</cfif>
<!--- THE FORM --->
<form method="post">
<fieldset name="col1">
<label for="message">Message:</label>
<textarea name="message">#form.message#</textarea>
<input type="submit" name="submit" value="Send Message" />
</fieldset>
<fieldset name="col2">
<label for="to">To:</label>
<input type="text" name="to" id="to" value="#form.to#" />
<label for="from">From:</label>
<input type="text" name="from" id="from" value="#form.from#" />
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="#form.username#" />
<label for="subject">Subject:</label>
<input type="text" name="subject" id="subject" value="#form.subject#" />
<label for="password">Password:</label>
<input type="text" name="password" id="password" value="#form.password#" />
<label for="server">Server:</label>
<input type="text" name="server" id="server" value="#form.server#" />
<label for="port">Port:</label>
<input type="text" name="port" id="port" value="#form.port#" />
<label>useSSL:</label>
<label class="inline" for="useSSLyes"><input type="radio" name="useSSL" id="useSSLyes" value="true" <cfif YesNoFormat(form.useSSL)> checked="checked"</cfif> /> Yes</label>
<label class="inline" for="useSSLno"><input type="radio" name="useSSL" id="useSSLno" value="false" <cfif !YesNoFormat(form.useSSL)> checked="checked"</cfif> /> No</label>
<label>useTLS:</label>
<label class="inline" for="useTLSyes"><input type="radio" name="useTLS" id="useTLSyes" value="true" <cfif YesNoFormat(form.useTLS)> checked="checked"</cfif> /> Yes</label>
<label class="inline" for="useTLSno"><input type="radio" name="useTLS" id="useTLSno" value="false" <cfif !YesNoFormat(form.useTLS)> checked="checked"</cfif> /> No</label>
<label>useDefaultSMTP:</label>
<label class="inline" for="useDefaultSMTPyes"><input type="radio" name="useDefaultSMTP" id="useDefaultSMTPyes" value="true" <cfif YesNoFormat(form.useDefaultSMTP)> checked="checked"</cfif> /> Yes</label>
<label class="inline" for="useDefaultSMTPno"><input type="radio" name="useDefaultSMTP" id="useDefaultSMTPno" value="false" <cfif !YesNoFormat(form.useDefaultSMTP)> checked="checked"</cfif> /> No</label>
</fieldset>
</form>
</cfoutput>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment