Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action email : Reply Adresse als Parameter hinzufügen #1506

Open
dalliclick opened this issue May 14, 2024 · 0 comments
Open

Action email : Reply Adresse als Parameter hinzufügen #1506

dalliclick opened this issue May 14, 2024 · 0 comments

Comments

@dalliclick
Copy link

Bei der Verwendung der action in Kontaktformularen, lassen es die Policies von vielen Hostern nicht mehr zu, daß die from Adresse auf den Wert eines email Feldes des Formulars gesetzt wird. Hier wäre ein zusätzlicher Parameter für eine reply Adresse nützlich, auch wenn das eine gewisse Aufmerksamkeit des Benutzers erfordert, der die Mail beantwortet.

Besonders praktisch, wenn der Wert für den Parameter auch noch optional das Format NAME<MAILADRESSE> haben kann.

Hier wäre der von mir dazu geschriebene Code

`
class rex_yform_action_email extends rex_yform_action_abstract
{

    public function executeAction(): void
    {
        // see getDescription() below
        $aFormParams = array(
            'from' => $this->getElement(2),
            'reply' => $this->getElement(3),
            'to' => $this->getElement(4),
            'subject' => $this->getElement(5),
            'body' => $this->getElement(6)
        );

        // Arrays fuer Suchpattern und Ersetzung erstellen
        $aPregData = array();
        foreach ($this->params['value_pool']['email'] as $search => $replace) {
            $aPregData['pattern'][] = ":[#]{3}" . $search . "[#]{3}:";
            $aPregData['replace'][] = $replace;
            // wenn in +++ eingeschlossen -> urlencode() verwenden
            $aPregData['pattern'][] = ":[+]{3}" . $search . "[+]{3}:";
            $aPregData['replace'][] = urlencode($replace);
        }

        // Werte ersetzen
        foreach ($aFormParams as $label => $value) {
            $aFormParams[$label] = preg_replace($aPregData['pattern'], $aPregData['replace'], $aFormParams[$label]);
        }

        $mail = new rex_mailer();
        $mail->AddAddress($aFormParams['to'], $aFormParams['to']);

        // reply zerlegen in Name und Adresse
        if (! preg_match(":(.*)\<(.*)\>:", $aFormParams['reply'], $aHits)) {
            // nur Adresse
            $aReply = array("addr"=>$aFormParams['reply'],"name"=>"");
        }
        else {
            // Adresse & Name
            $aReply = array("addr"=>$aHits[2],"name"=>$aHits[1]);
        }
        $mail->AddReplyTo($aReply['addr'], $aReply['name']);

        $mail->WordWrap = 80;
        $mail->FromName = $aFormParams['from'];
        $mail->From = $aFormParams['from'];
        $mail->Sender = $aFormParams['from'];
        $mail->Subject = $aFormParams['subject'];
        $mail->Body = nl2br($aFormParams['body']);
        $mail->AltBody = strip_tags($aFormParams['body']);
        if (isset($this->params['value_pool']['email_attachments']) && is_array($this->params['value_pool']['email_attachments'])) {
            foreach ($this->params['value_pool']['email_attachments'] as $v) {
                $mail->AddAttachment($v[1], $v[0]);
            }
        }
        // $mail->IsHTML(true);
        $mail->Send();
    }

    public function getDescription(): string
    {
        return 'action|email|[email protected]|[ReplyName]&lt;[email protected]&gt;|[email protected]|Mailsubject|Mailbody###name###';
    }
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant