function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
calvin_nrcalvin_nr 

Can VF/apex be used to create simple EMAIL feedback form?

I am developing a site in Visualforce and would like to offer user a simple form to send me feedback via email. There would be 3-4 fields like name, user's email, reason and feedback and "send" button. Clicking the send button should automatically send that message to my email address.

I do not want to store the form data in salesforce at least for now...All the stuff I found online about visualforce/apex and email is about saving that data to salesforce too.

Can I just make use of apex's email capabilities and send out email without storing that data anywhere in salesforce?

Thanks,

Calvin

Best Answer chosen by Admin (Salesforce Developers) 
calvin_nrcalvin_nr

Ok looks like it can be done. Apex does provide email capabilities.

 

public with sharing class osv_portal_SendFeedbackEmail 
{
	public String emailTo {get; set;}
	public String emailBody {get; set;}
	public String response {get; set;}
	 
	public PageReference sendEmail()
	{
		Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		mail.setToAddresses(new String[] {emailTo});
		mail.setReplyTo('noreply@yourcompany.com');
		mail.setSenderDisplayName('Your Company Name');
		mail.setSubject('Test Email From Force.com Sites');
		mail.setPlainTextBody(emailBody);
		try
		{
			Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
			if(resultMail[0].isSuccess())      
				response = 'ok sent!';
			else
			{
				response = resultMail[0].getErrors().get(0).getMessage();
			}
		}
		catch(System.EmailException ex)
		{
			response = ex.getMessage();
		}  
		return null;
	}
	
}

 

All Answers

calvin_nrcalvin_nr

Ok looks like it can be done. Apex does provide email capabilities.

 

public with sharing class osv_portal_SendFeedbackEmail 
{
	public String emailTo {get; set;}
	public String emailBody {get; set;}
	public String response {get; set;}
	 
	public PageReference sendEmail()
	{
		Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		mail.setToAddresses(new String[] {emailTo});
		mail.setReplyTo('noreply@yourcompany.com');
		mail.setSenderDisplayName('Your Company Name');
		mail.setSubject('Test Email From Force.com Sites');
		mail.setPlainTextBody(emailBody);
		try
		{
			Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
			if(resultMail[0].isSuccess())      
				response = 'ok sent!';
			else
			{
				response = resultMail[0].getErrors().get(0).getMessage();
			}
		}
		catch(System.EmailException ex)
		{
			response = ex.getMessage();
		}  
		return null;
	}
	
}

 

This was selected as the best answer
developer_novicedeveloper_novice

Hi,

 

I am fumbling my way through documentation trying to learn how to be a developer! Fun, but not particularly productive :)

 

What is the process to create the feedback form; from start to finish?

 

Thanks!

 

Developer_Novice