Copy link to clipboard
Copied
Hi everyone,
I've been racking my brain on this for hours and I still haven't been able to figure it out. I feel like it should be fairly simple.
I've got a form that asks a user for an email address. When the form is submitted, the data is sent to an email address. If the user gives an email address, I want the recipient to be able to reply by hitting "reply" in their email client. Here's my code:
<cfoutput>
<cfif '#Form.EmailAddress#' neq ''>
<cfset EmailFrom = '#Form.FirstName# #Form.LastName#<#Form.EmailAddress#>'><cfelse>
<cfset EmailFrom = '#Form.FirstName# #Form.LastName#'>
</cfif>
</cfoutput>
<cfmail to="recipient" from="#EmailFrom#" subject="Appointment Request">
Everything's working at about 75%. If a user provides an email address, the form process works perfectly. However, if the user does not provide an email address, I simply want the "from" field in the email to output the first and last name. If not email address is provided, the process still works, but the first and last names are not output in the email "from" field. I get "<unknown sender>".
Does anyone have suggestions? I also tried a cfif statement in the cfmail string, but CF throws an error when I try to the run the script.
Thanks!
Copy link to clipboard
Copied
Right before your cfmail tag and right before you close your cfoutput put in #EmailFrom# <cfabort> and see what is there. I think the problem is in this line
<cfif '#Form.EmailAddress#' neq ''>
Take away the single quotes from the left side. For that matter, you don't need the pound signs either.
Copy link to clipboard
Copied
mchedester,
Thanks for the tip. Even with quotes and pound signs gone, there is still no name in the "from" field.
Copy link to clipboard
Copied
As Ian implied, you need a valid email address in the From attribute of a cfmail tag. Therefore, not only do you have to check that the form field is not empty, you have to ensure it's a valid email address. You can do that on the form with validate="email" and on the action page with isValid().
Copy link to clipboard
Copied
Thanks, Dan. Like I said in my original email, if a user enters an email address, the cfmail script works as it should. If I open Outlook, for example, the email that comes from the form has the user's name in the "from" column, and if I hit reply, it works perfectly. The only reason it wouldn't work perfectly is if the user enters an invalid email address. That's not something I'm worried about at this point.
What's not happening is when someone does not enter an email address (or any data) in the EmailAddress field, I wan't to set the EmailFrom variable to only output FirstName and LastName in Outlook's "from" column. For whatever reason, the "from" always come through as blank or unknown.
Thanks again for any help.
Copy link to clipboard
Copied
That is what Dan and I are saying, you can't just make the "EmailFrom variable to only output FirstName and LastName". The ColdFusion e-mail engine is validating that field to be a correctly formated email address. If it fails it will put "unknown sender" in there.
Copy link to clipboard
Copied
Interesting. I was using this format because I've succeeded using similar formats before. What I didn't realize was that I was just using firstname, lastname, or email address by itself. I tried just lastname and it worked. Maybe the space between the firstname and lastname is what throws it off.
Thanks for everyones' input!
Copy link to clipboard
Copied
The system is checking for an email address, not just a name.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more