4

メールの件名にクライアントの名前を設定しようとしています。これは私のアプリケーションにとって非常に重要であり、 SendGrid API ドキュメントで読んだことから、 それはかなり可能です! .

情報 - 置換タグは、メールの本文だけでなく、件名でも機能します。

問題は、私がこれを達成できていないように見えることです。最初は、電子メールの本文内で既に %name% サブルーチンを使用しているためではないかと考えたので、新しい置換パラメーター名 %nameSubject% を作成しましたが、機能しません。

私は次のコードを使用していますが、メール内の残りのパラメーターは正常に機能しています。

    /**
    @description Wrapper method in order to handle possible exception due to programmer\ maintainer errors.
    A part of a small wrapper class that I have designed to allow 1-line comfortable use of the the SendGrid and transport classes.
   @returns int - 1, unless there is an internal error, or an exception thrown
    */
public function execute(){
    if(!class_exists('SendGrid') || !class_exists('SendGrid\Mail')){
        throw new exception('Dependency exception SendGrid or SendGrid\Mail are not included');
    }
    if(!isset($this->mailingList) && empty($this->mailingList) || sizeof($this->mailingList) == 0){
        throw new exception('Cannot send an email to an empty set of addresses');
    }
    if(!isset($this->subject, $this->body) || empty($this->subject) || empty($this->body)){
        throw new exception('Cannot send an email without both a subject and a body');
    }

    $sendgrid = new SendGrid(SENDGRID_USER, SENDGRID_PASSWORD);

    // $this->importMailList();
    foreach($this->mailingList as $key => $val) {   
        $this->mail->addTo($key, $val);
    }
    $this->mail->
    setFrom($this->fromMail)-> 
    setSubject($this->subject)->
    setText($this->text)->
    setHtml($this->body);
    if(preg_match('/%name%/', $this->body) && !array_filter($this->mailingList, 'is_int') ){
        $this->mail->addSubstitution("%name%", array_values($this->mailingList));
    }
    return $sendgrid->smtp->send($this->mail);

}

どんな助けでも大歓迎です!.

4

1 に答える 1