lib/mail/Mail.php
private function addRecipientEmail(
        $emailType,
        $email,
        $name = null,
        $substitutions = null,
        $personalizationIndex = null,
        $personalization = null
    ) {
        $personalizationFunctionCall = "add" . $emailType;
        $emailType = "\SendGrid\Mail\\" . $emailType;
        if (!($email instanceof $emailType)) {
            $email = new $emailType(
                $email,
                $name,
                $substitutions
            );
        }
        if ($personalization != null) {
            $personalization->$personalizationFunctionCall($email);
            if ($subs = $email->getSubstitutions()) {
                foreach ($subs as $key => $value) {
                    $personalization->addSubstitution($key, $value);
                }
            }
            $this->addPersonalization($personalization);
            return;
        } else {
            if (isset($personalizationIndex)
                && !isset($this->personalization[$personalizationIndex])
            ) {
                // TODO: We should only do this if there exists an index
                // previous. For example, if given an index 3 and there is
                // no index 2, we should throw an error.
                $this->personalization[$personalizationIndex]
                    = new Personalization();
            }
            if ($this->personalization[0] != null && $personalizationIndex == 0) {
                $this->personalization[0]->$personalizationFunctionCall($email);
                if ($subs = $email->getSubstitutions()) {
                    foreach ($subs as $key => $value) {
                        $this->personalization[0]->addSubstitution($key, $value);
                    }
                }
                return;
            } else if ($this->personalization[$personalizationIndex] != null) {
                $this->personalization[$personalizationIndex]->$personalizationFunctionCall($email);
                if ($subs = $email->getSubstitutions()) {
                    foreach ($subs as $key => $value) {
                        $this->personalization[$personalizationIndex]->addSubstitution(
                            $key,
                            $value
                        );
                    }
                }
                return;
            } else {
                $personalization = new Personalization();
                $personalization->$personalizationFunctionCall($email);
                if ($subs = $email->getSubstitutions()) {
                    foreach ($subs as $key => $value) {
                        $personalization->addSubstitution($key, $value);
                    }
                }
                if (($personalizationIndex != 0)
                    && ($this->getPersonalizationCount() <= $personalizationIndex)
                ) {
                    $this->personalization[$personalizationIndex] = $personalization;
                } else {
                    $this->addPersonalization($personalization);
                }
                return;
            }
        }
    }
private function addRecipientEmail(
        $emailType,
        $email,
        $name = null,
        $substitutions = null,
        $personalizationIndex = null,
        $personalization = null
    ) {
        $personalizationFunctionCall = "add" . $emailType;
        $emailType = "\SendGrid\Mail\\" . $emailType;
        if (!($email instanceof $emailType)) {
            $email = new $emailType(
                $email,
                $name,
                $substitutions
            );
        }
        if ($personalization != null) {
            $personalization->$personalizationFunctionCall($email);
            if ($subs = $email->getSubstitutions()) {
                foreach ($subs as $key => $value) {
                    $personalization->addSubstitution($key, $value);
                }
            }
            $this->addPersonalization($personalization);
            return;
        } else {
            if (isset($personalizationIndex)
                && !isset($this->personalization[$personalizationIndex])
            ) {
                // TODO: We should only do this if there exists an index
                // previous. For example, if given an index 3 and there is
                // no index 2, we should throw an error.
                $this->personalization[$personalizationIndex]
                    = new Personalization();
            }
            if ($this->personalization[0] != null && $personalizationIndex == 0) {
                $this->personalization[0]->$personalizationFunctionCall($email);
                if ($subs = $email->getSubstitutions()) {
                    foreach ($subs as $key => $value) {
                        $this->personalization[0]->addSubstitution($key, $value);
                    }
                }
                return;
            } else if ($this->personalization[$personalizationIndex] != null) {
                $this->personalization[$personalizationIndex]->$personalizationFunctionCall($email);
                if ($subs = $email->getSubstitutions()) {
                    foreach ($subs as $key => $value) {
                        $this->personalization[$personalizationIndex]->addSubstitution(
                            $key,
                            $value
                        );
                    }
                }
                return;
            } else {
                $personalization = new Personalization();
                $personalization->$personalizationFunctionCall($email);
                if ($subs = $email->getSubstitutions()) {
                    foreach ($subs as $key => $value) {
                        $personalization->addSubstitution($key, $value);
                    }
                }
                if (($personalizationIndex != 0)
                    && ($this->getPersonalizationCount() <= $personalizationIndex)
                ) {
                    $this->personalization[$personalizationIndex] = $personalization;
                } else {
                    $this->addPersonalization($personalization);
                }
                return;
            }
        }
    }
private function addRecipientEmail ( $ emailType , $ email , $ name = null , $ substitutions = null , $ personalizationIndex = null , $ personalization = null ) { $ personalizationFunctionCall = "add" . $ emailType ; $ emailType = "\SendGrid\Mail\\" . $ emailType ; if ( ! ( $ email instanceof $ emailType ) ) { $ email = new $ emailType ( $ email , $ name , $ substitutions ) ; } if ( $ personalization != null ) { $ personalization -> $ personalizationFunctionCall ( $ email ) ; if ( $ subs = $ email -> getSubstitutions ( ) ) { foreach ( $ subs as $ key => $ value ) { $ personalization -> addSubstitution ( $ key , $ value ) ; } } $ this -> addPersonalization ( $ personalization ) ; return ; } else { if ( isset ( $ personalizationIndex ) && ! isset ( $ this -> personalization [ $ personalizationIndex ] ) ) { // TODO: We should only do this if there exists an index // previous. For example, if given an index 3 and there is // no index 2, we should throw an error. $ this -> personalization [ $ personalizationIndex ] = new Personalization ( ) ; } if ( $ this -> personalization [ 0 ] != null && $ personalizationIndex == 0 ) { $ this -> personalization [ 0 ] -> $ personalizationFunctionCall ( $ email ) ; if ( $ subs = $ email -> getSubstitutions ( ) ) { foreach ( $ subs as $ key => $ value ) { $ this -> personalization [ 0 ] -> addSubstitution ( $ key , $ value ) ; } } return ; } else if ( $ this -> personalization [ $ personalizationIndex ] != null ) { $ this -> personalization [ $ personalizationIndex ] -> $ personalizationFunctionCall ( $ email ) ; if ( $ subs = $ email -> getSubstitutions ( ) ) { foreach ( $ subs as $ key => $ value ) { $ this -> personalization [ $ personalizationIndex ] -> addSubstitution ( $ key , $ value ) ; } } return ; } else { $ personalization = new Personalization ( ) ; $ personalization -> $ personalizationFunctionCall ( $ email ) ; if ( $ subs = $ email -> getSubstitutions ( ) ) { foreach ( $ subs as $ key => $ value ) { $ personalization -> addSubstitution ( $ key , $ value ) ; } } if ( ( $ personalizationIndex != 0 ) && ( $ this -> getPersonalizationCount ( ) <= $ personalizationIndex ) ) { $ this -> personalization [ $ personalizationIndex ] = $ personalization ; } else { $ this -> addPersonalization ( $ personalization ) ; } return ; } } }
Adds a To, Cc or Bcc object to a Personalization object

@param string $emailType Object type name:
To, Cc or Bcc
@param string $email Recipient email
address
@param string|null $name Recipient name
@param Substitution[]|array|null $substitutions Personalized
substitutions
@param int|null $personalizationIndex Index into an array
of existing
Personalization
objects
@param Personalization|null $personalization A pre-created
Personalization object

@return null
Adds a To Cc or Bcc object to a Personalization object