Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFMAIL and Databases

Status
Not open for further replies.

clustcant

Technical User
Feb 3, 2003
2
US
When using <cfmail> to bulk mail from the database, how can blank email fields within the database be skipped so as not to receive a NULL VALUE error message?
I know <cfif> is the key but how to implement?
 
<cfif databasefield EQ &quot;&quot;>
<cfelse>
#databasefield#
</cfif>

or

<cfif databasefield IS NULL>
<cfelse>
#databasefield#
</cfif>

Follow for each time you want to print a value. DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Right, but if you're using
Code:
<CFMAIL query=&quot;nameOfSomeQuery&quot; ...>
you don't really have the opportunity to do a CFIF for the email address (if you're using it for the &quot;to&quot; field).

The trick is to set your query up so it doesn't have any null values for the email address to begin with:
Code:
<CFQUERY name=&quot;bulkmail&quot; ...>
  SELECT 
     emailaddress AS email
          :
  WHERE
     emailaddress IS NOT NULL
  AND
     emailaddress <> ''
          :
</CFQUERY>

<CFMAIL query=&quot;bulkmail&quot; to=&quot;#email#&quot; ...>
          :
</CFMAIL>

Hope it helps,
-Carl
 
I read &quot;blank fields&quot; missed the &quot;email&quot;.

Brain Dump!
[bigsmile] DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Does this solution include inside the subject line?

I am placing a value from the database in the subject line of the email that is sent, if the value is NULL, will the message be sent anyway excluding the value?
 
balooDog-

Depends on what field you're pulling from the database and inserting in the subject line. If its the e-mail address, then yes, the solution above will fly. If its some other field, just have the query remove any records with a NULL or &quot;&quot; value in that field, too, and you're golden.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top