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
deepu.sandeepdeepu.sandeep 

sending email

Hi

I have created afield called Email in vf page and a button sendemail, this is for custom object

Now my problem is i want to send an e-mail to the mail whatever i have given in email field when i click a sendemail button.How could i d datb  can any one send me code i am a newbie to salesforce

SRKSRK

<apex:page>

 <apex:form>

  <apex:inputfield value="{!emailto}" Name="Email"/>

<apex:commandbutton action = "{!SendEmail}" />

</apex:form>

<script>

    if({!emailsentflag})

     alert("email sent sucess");

</script>

</apex:page>

 

public class test

{

    public boolean emailsentflag{get;set;}

public string emailto{get;set;}

    public test()

   {

     emailsentflag = false;

     emailto = '';

   }

    public Pagereference SendEmail()

    {

          Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
          email.setToAddresses(emailto);
          String table = "<table> <tr><td>Hello this is test mail</td></tr> </table>
          email.setHtmlBody(table);
          email.setSubject('Help Required from ' + objVCD.Help_Required_from__c);
          Messaging.sendEmail(new  Messaging.SingleEmailMessage[] {email});

          emailsentflag= true;

          return null

    }

}

deepu.sandeepdeepu.sandeep

Hi SRK

              this is not working here i am sending my code please review dis and suggest me

vf page

 

<apex:page controller="logincntrlr" sidebar="false">
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:form ><br /><br /><br />


<table cellpadding="5">
<tr><td><b>Already Registered User</b> Sign-in</td>
    <td><b>New User</b> Sign-up</td>
</tr>
<tr>
<td>
 <table>
  <tr>
   <td><b><apex:outputLabel for="User Name">User Name:</apex:outputLabel></b></td>
   <td><apex:inputField value="{!l.Name}" required="true"/></td>
  </tr>
                  
  <tr>
   <td><b><apex:outputLabel for="Password">Password:</apex:outputLabel></b></td>
   <td><b><apex:inputsecret value="{!l.password__c}" required="true" /></b></td>
  </tr>
    <td></td>
  <tr><td><apex:commandButton value="Sign-in" action="{!save}"/></td></tr>
 </table>
</td>
           <td>
           <table cellspacing="0">
           <tr>
           <td><b><apex:outputLabel for="First Name">First Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.First_Name__c}"/></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="Last Name">Last Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Last_Name__c}" /></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="E-Mail">E-Mail:</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Email__c}" /></b></td>
           </tr>
                   
           <tr><td><apex:commandButton value="Sign-up" action="{!signup}"/></td></tr>
           </table>
           </td>
</tr>

</table>


</apex:form>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:page>

 

--------------------------------------------------------]

controller

 

public with sharing class logincntrlr {

    
    

    public PageReference signup() {
          
        return null;
    }

public Logins__c l{get;set;}
    public PageReference save()
     {
        
        pagereference p = new pagereference('/apex/endeavor2012regform2');
        p.setredirect(true);         
        return p;
     }


}

 

 

i need to send email to dat email field how can i do dat suggest me.

SRKSRK

U want to send a mail when it save the record ??

SRKSRK

I belive it on "signup" ??

SRKSRK

If u want it on singUp try this

apex:page controller="logincntrlr" sidebar="false">
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:form ><br /><br /><br />
<table cellpadding="5">
<tr><td><b>Already Registered User</b> Sign-in</td>
    <td><b>New User</b> Sign-up</td>
</tr>
<tr>
<td>
 <table>
  <tr>
   <td><b><apex:outputLabel for="User Name">User Name:</apex:outputLabel></b></td>
   <td><apex:inputField value="{!l.Name}" required="true"/></td>
  </tr>
                  
  <tr>
   <td><b><apex:outputLabel for="Password">Password:</apex:outputLabel></b></td>
   <td><b><apex:inputsecret value="{!l.password__c}" required="true" /></b></td>
  </tr>
    <td></td>
  <tr><td><apex:commandButton value="Sign-in" action="{!save}"/></td></tr>
 </table>
</td>
           <td>
           <table cellspacing="0">
           <tr>
           <td><b><apex:outputLabel for="First Name">First Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.First_Name__c}"/></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="Last Name">Last Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Last_Name__c}" /></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="E-Mail">E-Mail:</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Email__c}" /></b></td>
           </tr>
                   
           <tr><td>
           <apex:commandButton value="Sign-up" action="{!signup}"/></td></tr>
           </table>
           </td>
</tr>

</table>


</apex:form>
</apex:pageBlockButtons>
</apex:pageBlock>
<script>

    if({!emailsentflag})

     alert("email sent sucess");

</script>
</apex:page>

 

------------------------------CLASS-------------------------
 
public with sharing class logincntrlr
 {
    public boolean emailsentflag{get;set;}
    public PageReference signup()
    {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
        email.setToAddresses(l.Email__c);
        String table = "<table> <tr><td>Hello this is test mail</td></tr> </table>
        email.setHtmlBody(table);
        email.setSubject('Help Required from ' + objVCD.Help_Required_from__c);
        Messaging.sendEmail(new  Messaging.SingleEmailMessage[] {email});  
        emailsentflag = true;
        return null;
    }

public Logins__c l{get;set;}
    public PageReference save()
     {
        pagereference p = new pagereference('/apex/endeavor2012regform2');
        p.setredirect(true);         
        return p;
     }


}

deepu.sandeepdeepu.sandeep

yes i want to send a mail on clicking a sign-up and then i want to save a record to contact with firstnsme,lastname,email whatever i have created in vf page. how could i do this suggest me.

deepu.sandeepdeepu.sandeep

Hi

   I have already tried this but i am getting errors like dis

ErrorError: logincntrlr Compile Error: Variable does not exist: objVCD.Help_Required_from__c at line 11 column 50

 

if i remove dat line and i am getting this error

 

ErrorError: logincntrlr Compile Error: Method does not exist or incorrect signature: [Messaging.SingleEmailMessage].setToAddresses(String) at line 8 column 9

 

suggest me. what to do.

SRKSRK

just share u r complite apex class & i will fix it for u  :)

SRKSRK

just replace u r signup method with this one

 

public PageReference signup()
    {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  

        String [] toAddresses = new String[] {l.Email__c};
        email.setToAddresses(toAddresses );
        String table = "<table> <tr><td>Hello this is test mail</td></tr> </table>
        email.setHtmlBody(table);
        email.setSubject('Test EMail');
        Messaging.sendEmail(new  Messaging.SingleEmailMessage[] {email});  
        emailsentflag = true;
        return null;
    }

deepu.sandeepdeepu.sandeep

Hi SRK,

                i am not getting mail for this code hre i am sharing my complete code review this and fix it for me

what i need is i want to send an usernamw and password to the new user who is signing up to the field vslue of email

and then a record has to save to cintact object with fname,lname,email whatever he has given at the time of signing up

 

please fix it for me.

 

vfpage

--------------------------------------

<apex:page controller="logincntrlr" sidebar="false">
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:form ><br /><br /><br />


<table cellpadding="5">
<tr><td><b>Already Registered User</b> Sign-in</td>
    <td><b>New User</b> Sign-up</td>
</tr>
<tr>
<td>
 <table>
  <tr>
   <td><b><apex:outputLabel for="User Name">User Name:</apex:outputLabel></b></td>
   <td><apex:inputField value="{!l.Name}" required="true"/></td>
  </tr>
                  
  <tr>
   <td><b><apex:outputLabel for="Password">Password:</apex:outputLabel></b></td>
   <td><b><apex:inputsecret value="{!l.password__c}" required="true" /></b></td>
  </tr>
    <td></td>
  <tr><td><apex:commandButton value="Sign-in" action="{!save}"/></td></tr>
 </table>
</td>
           <td>
           <table cellspacing="0">
           <tr>
           <td><b><apex:outputLabel for="First Name">First Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.First_Name__c}"/></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="Last Name">Last Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Last_Name__c}" /></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="E-Mail">E-Mail:</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Email__c}" /></b></td>
           </tr>
                   
           <tr><td><apex:commandButton value="Sign-up" action="{!signup}"/></td></tr>
           </table>
           </td>
</tr>

</table>


</apex:form>
</apex:pageBlockButtons>
</apex:pageBlock>
<script>

    if({!emailsentflag})

     alert("email sent sucess");

</script>
</apex:page>

 

 

controller

--------------------------------------------------------

public with sharing class logincntrlr {

    
    
    public boolean emailsentflag{get;set;}
    public PageReference signup()
    {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  

        String [] toAddresses = new String[] {l.Email__c};
        email.setToAddresses(toAddresses );
        String table = '<table> <tr><td>Hello this is test mail</td></tr> </table>';
        email.setHtmlBody(table);
        email.setSubject('Test EMail');
        Messaging.sendEmail(new  Messaging.SingleEmailMessage[] {email});  
        emailsentflag = true;
        return null;
    }

public Logins__c l{get;set;}
    public PageReference save()
     {
        insert l;
        pagereference p = new pagereference('/apex/endeavor2012regform2');
        p.setredirect(true);         
        return p;
     }


}

 

 

 

SRKSRK

ok i look into it

can u do one thing just add some system.debug('@@@@@@@@@@@@@@'+l.Email__c); inside the singup mehtod & let me know what it was showing

deepu.sandeepdeepu.sandeep

ya i tried system.debug('@@@@@@@@@@@@@@'+l.Email__c);

there is no impact bcoz of dis its showing noting in debuglogs ihave seen in debuglogs output.

SRKSRK

hmmm it means that the method is not called up

SRKSRK

try this VF page

<apex:page controller="logincntrlr" sidebar="false">
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Sign-in" action="{!save}"/>
<apex:commandButton value="Sign-up" action="{!signup}"/>
</apex:pageBlockButtons>
<apex:form ><br /><br /><br />


<table cellpadding="5">
<tr><td><b>Already Registered User</b> Sign-in</td>
    <td><b>New User</b> Sign-up</td>
</tr>
<tr>
<td>
 <table>
  <tr>
   <td><b><apex:outputLabel for="User Name">User Name:</apex:outputLabel></b></td>
   <td><apex:inputField value="{!l.Name}" required="true"/></td>
  </tr>
                  
  <tr>
   <td><b><apex:outputLabel for="Password">Password:</apex:outputLabel></b></td>
   <td><b><apex:inputsecret value="{!l.password__c}" required="true" /></b></td>
  </tr>
    <td></td>
  <tr><td></td></tr>
 </table>
</td>
           <td>
           <table cellspacing="0">
           <tr>
           <td><b><apex:outputLabel for="First Name">First Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.First_Name__c}"/></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="Last Name">Last Name</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Last_Name__c}" /></b></td>
           </tr>
           <tr>
           <td><b><apex:outputLabel for="E-Mail">E-Mail:</apex:outputLabel></b></td>
           <td><b><apex:inputfield value="{!l.Email__c}" /></b></td>
           </tr>
                   
           <tr><td></td></tr>
           </table>
           </td>
</tr>

</table>


</apex:form>

</apex:pageBlock>
<script>

    if({!emailsentflag})

     alert("email sent sucess");

</script>
</apex:page>