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
geetha b 8geetha b 8 

I need to send an email when a button is clicked in vf page can any one help me

RishavRishav
Hii,
 i have made this program for practice purpose , you can customize it  according to your need
<apex:form id="emailForm">
  <a href="#" id="emailUs">Email Us</a>
  <apex:outputLink value="/apex/trialAndError?id=0019000000wE7hz"> trialAndError</apex:outputLink>
 <div id="overlay" class="web_dialog_overlay"></div>
    
<div id="dialog" class="web_dialog">
   <table style="width: 100%; border: 0px;" cellpadding="3" cellspacing="0">
      <tr>
         <td class="web_dialog_title">Email</td>
         <td class="web_dialog_title align_right">
           <button class="close-icon" id="btnClose"></button>
         </td>
      </tr>
      <tr><td> </td> <td> </td> </tr> <!-- for blank space -->

    <tr> 
        <td class="emailLabel"><apex:outputLabel value="First Name"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputText value="{!cust_fname}"  size="24"/></td>
    </tr>   
     
       <tr> 
        <td class="emailLabel"><apex:outputLabel value="Last Name"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputText value="{!cust_Lname}"  size="24"/></td>
    </tr> 
     <tr> 
        <td class="emailLabel"><apex:outputLabel value="Company"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputText value="{!cust_company}"  size="24"/></td>
    </tr>  
    <tr> 
        <td class="emailLabel"><apex:outputLabel value="Phone Number"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputText value="{!cust_Phone}"  size="24"/></td>
    </tr> 
     <tr> 
        <td class="emailLabel"><apex:outputLabel value="Email"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputText value="{!cust_Email}"  size="24"/></td>
    </tr>
     <tr> 
        <td class="emailLabel"><apex:outputLabel value="Subject"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputText value="{!Email_subject}"  size="24"/></td>
    </tr>
     <tr> 
        <td class="emailLabel"><apex:outputLabel value="Country"></apex:outputLabel>   </td>
        <td class="emailText">
         <apex:selectList value="{!countries}" size="1">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList>
        </td>
    </tr>
     <tr> 
        <td class="emailLabel"><apex:outputLabel value="Question/Comments"></apex:outputLabel>   </td>
        <td class="emailText"><apex:inputTextArea value="{!cust_Comments}"/></td>
    </tr>
    </table><br/>
      <apex:commandButton value="Send Mail" action="{!SendMail}" oncomplete="CloseAndRefresh();" style="margin-left:34%;padding:5px;margin-bottom:10px;"/>
    <apex:outputText value="{!cust_company}"></apex:outputText>
</div>
 </apex:form>
 
 ===============================
 
 public class emailPopupSendMailTrial {

 public string cust_fname{get;set;}
    public string cust_lname{get;set;}
    public string cust_company{get;set;}
    public string cust_phone{get;set;}
    public string cust_email{get;set;}
    public string cust_comments{get;set;}
    public string country{get;set;}
    String[] countries = new String[]{};
    public string Email_Subject{get;set;}    
    
    // code section for displaying the list of countries 
      public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            
            return options;
        }
            
        public String[] getCountries() {
            return countries;
        }
            
        public void setCountries(String[] countries) {
            this.countries = countries;
        }
    
    // end of the code section of list of countries
    
   // Code section for sending the mail after clicking on the send mail button
    
    public PageReference SendMail() {
        String[] recipients = new String[]{'dearrishav@gmail.com'};
    Messaging.reserveSingleEmailCapacity(recipients.size());
    Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
    msg.setToAddresses(recipients);
    msg.setSubject('Test Email Subject');
    msg.setHtmlBody('Test body including HTML markup');
    msg.setPlainTextBody('Test body excluding HTML markup');
    msg.setSaveAsActivity(false);
    msg.setUseSignature(false);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {msg}, false);
    
    cust_company= 'yes this function is working';
    return null;

}
}

Thanks 
Rishav