Hallo
Mein Web-Provider stellt bei seinen Mailkonten demnächst auf envelope-from um. Problem: Die Formulare auf meiner Webseite werden per Mail an mich gesendet, und die Mailadresse des Absenders wird als "from" eingetragen. Damit ich schnell und einfach antworten kann. Das scheint bei envelope-from nicht mehr möglich zu sein. Ich verschicke via SMTP über ein Mailkonto, welches ausschliesslich für diesen Zweck existiert.
Daher meine Frage: Wie liesse sich das lösen? Ginge das, wenn "from" wieder Standard wäre (also diese Mailadresse, die zum Senden benutzt wird) und zusätzlich ein Reply-To mit der Absenderadresse eingefügt wird? Die Webseite wurde nicht von mir erstellt, da ich mich in Sachen PHP nicht gut auskenne. Er hat das Template "MailHelper" benutzt.
Dies ist der Kot von MailHelper.php::
Und hier der vom Controller, wo das Senden initiiert wird:
Wenn das mit rely-To geht, wie müsste ich das machen? Denn das scheint im MailHelper nicht vorgesehen zu sein.
Besten Dank.
Mein Web-Provider stellt bei seinen Mailkonten demnächst auf envelope-from um. Problem: Die Formulare auf meiner Webseite werden per Mail an mich gesendet, und die Mailadresse des Absenders wird als "from" eingetragen. Damit ich schnell und einfach antworten kann. Das scheint bei envelope-from nicht mehr möglich zu sein. Ich verschicke via SMTP über ein Mailkonto, welches ausschliesslich für diesen Zweck existiert.
Daher meine Frage: Wie liesse sich das lösen? Ginge das, wenn "from" wieder Standard wäre (also diese Mailadresse, die zum Senden benutzt wird) und zusätzlich ein Reply-To mit der Absenderadresse eingefügt wird? Die Webseite wurde nicht von mir erstellt, da ich mich in Sachen PHP nicht gut auskenne. Er hat das Template "MailHelper" benutzt.
Dies ist der Kot von MailHelper.php::
Code:
<?php
declare(strict_types=1);
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
class MailHelper
{
private PHPMailer $mail;
private string $ErrorInfo;
public function getErrorInfo(): string
{
return $this->ErrorInfo;
}
public function hasErrorInfo(): bool
{
return !empty($this->ErrorInfo);
}
public function __construct()
{
$this->mail = new PHPMailer(true);
$this->mail->CharSet = PHPMailer::CHARSET_UTF8;
$this->mail->isHTML(false);
}
/**
* @throws Exception
*/
public function toUser(string $subject,
string $body,
string $to_address,
string $to_name,
?string $from_address = null,
?string $from_name = null): PHPMailer
{
if (!$from_address) {
$from_address = MAIL_FROM_ADDRESS;
}
if (!$from_name) {
$from_name = MAIL_FROM_NAME;
}
// Validate to address
if (!filter_var($to_address, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Invalid to address "'.$to_address.'" for user');
}
// Validate from address
if (!filter_var($from_address, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Invalid from address "'.$from_address.'" for user');
}
return $this->handleMail(
subject: $subject,
body: $body,
to_address: $to_address,
to_name: $to_name,
from_address: $from_address,
from_name: $from_name
);
}
/**
* @throws Exception
*/
public function handleMail(string $subject,
string $body,
string $to_address,
string $to_name,
string $from_address,
string $from_name): PHPMailer
{
try {
/** For SMTP, change the following */
if (USE_SMTP) {
$this->mail->isSMTP();
if (DEBUG) {
$this->mail->SMTPDebug = SMTP::DEBUG_SERVER;
}
$this->mail->Host = SMTP_HOST;
$this->mail->SMTPAuth = true;
$this->mail->Username = SMTP_USERNAME;
$this->mail->Password = SMTP_PASSWORD;
$this->mail->SMTPSecure = SMTP_ENCRYPTION;
$this->mail->Port = SMTP_PORT;
} else {
$this->mail->isMail();
}
/** Add the BCC in case there are some given */
if (count(BCC_RECIPIENTS) > 0) {
foreach (BCC_RECIPIENTS as $bcc) {
// Validate BCC address
if (filter_var($bcc, FILTER_VALIDATE_EMAIL)) {
$this->mail->addBCC($bcc);
}
}
}
$this->mail->setFrom($from_address, $from_name);
$this->mail->addAddress($to_address, $to_name);
$this->mail->Subject = $subject;
$this->mail->Body = $body;
return $this->mail;
} catch (Exception $e) {
$this->ErrorInfo = $e->getMessage();
}
}
/**
* @throws Exception
*/
public function toAdmin(string $subject,
string $body,
?string $from_address = null,
?string $from_name = null): PHPMailer
{
if (!$from_address) {
$from_address = MAIL_FROM_ADDRESS;
}
if (!$from_name) {
$from_name = MAIL_FROM_NAME;
}
// Validate to address
if (!filter_var(MAIL_TO_ADDRESS, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Invalid to address "'.MAIL_TO_ADDRESS.'" for admin');
}
// Validate from address
if (!filter_var($from_address, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Invalid from address "'.$from_address.'" for admin');
}
return $this->handleMail(
subject: $subject,
body: $body,
to_address: MAIL_TO_ADDRESS,
to_name: MAIL_TO_ADDRESS_NAME,
from_address: $from_address,
from_name: $from_name
);
}
}
Code:
$mail = new MailHelper();
$mail->toAdmin(
subject: xxx,
body: $body,
from_address: $inputs['email'],
from_name: $inputs['name']
)->send();
Besten Dank.