You need to sign in to do that
Don't have an account?

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
<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
}
}
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.
U want to send a mail when it save the record ??
I belive it on "signup" ??
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;
}
}
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.
Hi
I have already tried this but i am getting errors like dis
if i remove dat line and i am getting this error
suggest me. what to do.
just share u r complite apex class & i will fix it for u :)
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;
}
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;
}
}
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
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.
hmmm it means that the method is not called up
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>