title: Docusign: How do I redirect a user after remote signing (email) to my site using PHP?
body: <p>I'm using Laravel 5.4 and the docusign/esign-client 3 package. On my site I redirect a user to a document in Docusign and then redirect them back to my site to download and update my database after theyve signed it. At the same time I send them an email. My question is how do I redirect them back to my site if they clicked on the email instead of landing on the document directly from my site?</p>
  
  <p>I've tried using the method <code>TemplateRole.setEmbeddedRecipientStartUrl</code> and it does redirect me prior to sending them to the document but I don't get any information about the envelope. Ideally I would like send them directly to docusign and then redirect them back to my site after signing when clicking the email. How do I do this? or whats the correct code to get this working?</p>
  
  <pre><code>      &lt;?php
   //fill in document fields
          $text_tabs = [];
          foreach($custom_fields as $custom_field_name=&gt;$custom_field_value){
              $text_tabs[] = (new \DocuSign\eSign\Model\Text())
                              -&gt;setTabLabel($custom_field_name)
                              -&gt;setValue($custom_field_value);
          }
  
          $tabs = (new \DocuSign\eSign\Model\Tabs())
                  -&gt;setTextTabs($text_tabs);
          //end fill in document fields
  
  
          // assign recipient to template role by setting name, email, and role name.  Note that the
          // template role name must match the placeholder role name saved in your account template.
          $templateRole = (new \DocuSign\eSign\Model\TemplateRole())
                          -&gt;setEmail($email)
                          -&gt;setName($name)
                          //-&gt;setEmbeddedRecipientStartUrl(route("test1"))
                          -&gt;setEmbeddedRecipientStartUrl("SIGN_AT_DOCUSIGN")//sends user directly to docusign
                          -&gt;setClientUserId($rand_user_id)
                          -&gt;setTabs($tabs)
                          -&gt;setRoleName("Applicant");
  
  
          //webhook config
          $envelope_events = [
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("sent"),
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("delivered"),
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("completed"),
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("declined"),
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("voided"),
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("sent"),
              (new \DocuSign\eSign\Model\EnvelopeEvent())-&gt;setEnvelopeEventStatusCode("sent")
          ];
  
          $recipient_events = [
              (new \DocuSign\eSign\Model\RecipientEvent())-&gt;setRecipientEventStatusCode("Sent"),
              (new \DocuSign\eSign\Model\RecipientEvent())-&gt;setRecipientEventStatusCode("Delivered"),
              (new \DocuSign\eSign\Model\RecipientEvent())-&gt;setRecipientEventStatusCode("Completed"),
              (new \DocuSign\eSign\Model\RecipientEvent())-&gt;setRecipientEventStatusCode("Declined"),
              (new \DocuSign\eSign\Model\RecipientEvent())-&gt;setRecipientEventStatusCode("AuthenticationFailed"),
              (new \DocuSign\eSign\Model\RecipientEvent())-&gt;setRecipientEventStatusCode("AutoResponded")
          ];
  
          /*NOTE *****
          //make sure to add route url to $except in Http\Middleware\VerifyCsrfToken*/
          $event_notification = (new \DocuSign\eSign\Model\EventNotification())
                                  -&gt;setUrl(route("webhook"))//url webhook goes to
                                  -&gt;setLoggingEnabled("true")
                                  -&gt;setRequireAcknowledgment("true")
                                  -&gt;setUseSoapInterface("false")
                                  -&gt;setIncludeCertificateWithSoap("false")
                                  -&gt;setSignMessageWithX509Cert("false")
                                  -&gt;setIncludeDocuments("true")
                                  -&gt;setIncludeEnvelopeVoidReason("true")
                                  -&gt;setIncludeTimeZone("true")
                                  -&gt;setIncludeSenderAccountAsCustomField("true")
                                  -&gt;setIncludeDocumentFields("true")
                                  -&gt;setIncludeCertificateOfCompletion("true")
                                  -&gt;setEnvelopeEvents($envelope_events)
                                  -&gt;setRecipientEvents($recipient_events);
          //end webhook config
  
  
  
  
  
  
  
          // instantiate a new envelope object and configure settings
          $envelop_definition = (new \DocuSign\eSign\Model\EnvelopeDefinition())
                                  -&gt;setEmailSubject("Docusign Test")
                                  -&gt;setTemplateId($template_id)
                                  -&gt;setTemplateRoles(array($templateRole))
                                  //-&gt;setRecipients($recipients)
                                  -&gt;setEventNotification($event_notification)
                                  -&gt;setStatus("sent");// set envelope status to "sent" to immediately send the signature request
  
  
          // optional envelope parameters
          $options = (new \DocuSign\eSign\Api\EnvelopesApi\CreateEnvelopeOptions())
                      -&gt;setCdseMode(null)
                      -&gt;setMergeRolesOnDraft(null);
  
          // create and send the envelope (aka signature request)
          $envelopeApi = new \DocuSign\eSign\Api\EnvelopesApi($this-&gt;api_client);
  
          $envelop_summary = $envelopeApi-&gt;createEnvelope($this-&gt;account_id, $envelop_definition, $options);
          if(!empty($envelop_summary)){
  
              $envelop_summary = json_decode($envelop_summary,true);
  
  
              $recipient_view_request = ( new \DocuSign\eSign\Model\RecipientViewRequest() )
                                          -&gt;setReturnUrl( route("return_url_for_document") )
                                          -&gt;setClientUserId($rand_user_id)
                                          -&gt;setAuthenticationMethod("email")
                                          -&gt;setUserName($name)
                                          -&gt;setEmail($email);
  
              try{
                  $signing_view = $envelopeApi-&gt;createRecipientView($this-&gt;account_id, $envelop_summary["envelopeId"], $recipient_view_request);
  
                  $signing_url                    = $signing_view-&gt;getUrl();
                  $envelop_summary["signing_url"] = $signing_url;
  
                  return $envelop_summary;
  
              } catch (\DocuSign\eSign\ApiException $e){
                  echo  "Error connecting Docusign : " . $e-&gt;getResponseBody()-&gt;errorCode . " " . $e-&gt;getResponseBody()-&gt;message;
              }
          }
  </code></pre>