Ich verschicke Mails per Phpmailer. Man kann sich bei dem Formualr die Mail auch selbst zuschicken lassen.Also gehen zwei Mails bei dem Script raus.
Die beiden nachrichten werden als Multipartmails verschickt also mit HTML und ohne.
Mein Problem ist nun das die zweite Mail im Antworttext immer das HTML und das ohne HTML ausgibt. ich komm nicht dahinter was ich falsch mache.
Muss ich den Body für die zweite Mail auch clearen? hab dazu jetzt aber nichts gefunden.
Die beiden nachrichten werden als Multipartmails verschickt also mit HTML und ohne.
Mein Problem ist nun das die zweite Mail im Antworttext immer das HTML und das ohne HTML ausgibt. ich komm nicht dahinter was ich falsch mache.
Muss ich den Body für die zweite Mail auch clearen? hab dazu jetzt aber nichts gefunden.
PHP:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
function sendMail() {
require 'plugins/vendor/phpmailer/phpmailer/src/Exception.php';
require 'plugins/vendor/phpmailer/phpmailer/src/PHPMailer.php';
$mail = new PHPMailer;
//Server settings
$mail->SMTPDebug = Config::APP_MAIL_SMTPDEBUG; // Enable verbose debug output
// if(Config::APP_MAIL_ISSMTP == true){ $mail->IsSMTP(); }
$mail->Host = Config::APP_MAIL_HOST; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = Config::APP_MAIL_PORT; //Sets the default SMTP server port
$mail->SMTPAuth = Config::APP_MAIL_SMTPAUTH; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = Config::APP_MAIL_USERNAME; //Sets SMTP username
$mail->Password = Config::APP_MAIL_PASSWORD; //Sets SMTP password
$mail->SMTPSecure = Config::APP_MAIL_SMTPSECURE; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->CharSet = Config::APP_MAIL_CHARSET;
$from_name = $_POST['contact_name'];
$from_nameTwo = Config::APP_MAIL_NAMEFROM;
$from_mail = $_POST['contact_email'];
$from_mailTwo = Config::APP_MAIL_FROM;
$replyto = $_POST['contact_email'];
$mailto = Config::APP_MAIL_FROM;
$subject = isset($_POST['contact_subject']) ? $_POST['contact_subject'] : Config::APP_MAIL_SUBJECT;
$subjectTwo = 'Kopie der Nachricht: »' . $subject . '«';
$message = $_POST['contact_message'];
$message = '<strong>Name:</strong> ' . $from_name . '<br /><strong>E-Mail:</strong> ' . $from_mail . '<br /><strong>Betreff:</strong> ' . $subject . '<br /><strong>Datenschutz annerkannt:</strong> ' . $_POST['contact_privacy'] . '<br /><strong>Kopie der Nachricht erhalten:</strong> ' . $_POST['contact_sendme'] . '<br /><strong>Nachricht:</strong> ' . str_replace("\n",'<br />',$message);
$messageNoHTML = 'Name: ' . $from_name . ' E-Mail: ' . $from_mail . ' Betreff: ' . $subject . ' Datenschutz annerkannt: ' . $_POST['contact_privacy'] . ' Kopie der Nachricht erhalten: ' . $_POST['contact_sendme'] . ' Nachricht: ' . $message;
$messageTwo =
$messageTwoNoHTML = 'Danke für Ihre E-Mail. Wir werden Ihnen so schnell wie möglich antworten! Name: ' . $from_name . ' E-Mail: ' . $from_mail . ' Betreff: ' . $subject . ' Datenschutz annerkannt: ' . $_POST['contact_privacy'] . ' Kopie der Nachricht erhalten: ' . $_POST['contact_sendme'] . ' Nachricht: ' . $message;
// 1.mail
$mail->From = $from_mail;
$mail->FromName = $from_name;
$mail->addAddress($mailto); // Add a "To" address
$mail->addReplyTo($replyto); // Antwortadresse festlegen
$mail->isHTML(true); // Mail als HTML versenden
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $messageNoHTML;
// 2.mail
if(isset($_POST['contact_sendme'])){
$mail->Send();
$mail->ClearAllRecipients();
$mail->clearReplyTos();
$mail->ClearAttachments();
$mail->From = $from_mailTwo;
$mail->FromName = $from_nameTwo;
$mail->addAddress($from_mail); // Add a "To" address
$mail->addReplyTo($mailto); // Antwortadresse festlegen
$mail->isHTML(true); // Mail als HTML versenden
$mail->Subject = $subjectTwo;
$mail->Body = $messageTwo;
$mail->AltBody = $messageTwoNoHTML;
}
try {
if(!$mail->Send()){
throw new Exception();
}
else {
unset($_POST);
echo '<div class="modalContainer"><div class="ownModal animated fadeInUp"><i class="fal fa-check-circle"></i><span class="msgText">Vielen Dank für Ihre E-Mail!<br />Wir werden Ihnen schnellstmöglich antworten.</span><button class="btn btn-transparent"><i class="fal fa-times"></i></button></div><div class="modalBG animated fadeIn"></div></div>';
// return '<div class="alert alert-danger">E-Mail wurde versendet!</div>';
}
} catch (Exception $e) {
return '<div class="alert alert-danger">Error: ' . $mail->ErrorInfo . '</div>';
}
}