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

Email Code makes Error on Sites

I wrote a wizard using the controller and it uses 4 visualforce pages to work. The last page is supposed to be rendered as a pdf. So I added in code to the controller that uses that pdf as an email attachment based of this model. I dont get any error when saving the code but when I access the Sites page it says I dont have authorization. How can I fix this? Note: Worked perfectly before I added in the red highlighted part of the code below.

public class GLeadExtension {
public Lead aLead ;
public GLeadExtension() {
ApexPages.StandardController controller;
aLead = new Lead() ;
public PageReference step1() {
return Page.mhform422;
public PageReference step2() {
return Page.mhformpt2422;
public PageReference step3() {
return Page.mhformpt3422;
public PageReference step4() {
return Page.mhformconfirm;
public PageReference step5() {
return Page.mhformendpage;
public PageReference home() {
return Page.FileNotFound;
public PageReference getPDF() {
PageReference pdf = Page.mhformconfirm;
Blob b = pdf.getContent();
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setSubject('From PDF');
String [] toAddresses = new String[] {''};
email.setPlainTextBody('Here is the body of the email');
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return Page.mhformendpage;



NEW: Found that the access was denied because the last page was rendered as a pdf. when i removed that code from the apex page it worked correctly on the site. But I need it to render as a pdf for the email code to work. How can this be done?