Skip to content

PHPMailer

Verschoben PHP
  • Installation

    Wenn man mit PHP Mails verschicken will, stößt man sehr oft auf die Empfehlung PHPMailer. Das scheint wohl die Maillösung für PHP zu sein. Ok, dann mal testen. Erste Schwierigkeit, wie downloaden? Da stößt man auf composer, das mal ausprobiert. Aber ehrlich gesagt, verstehe ich das nicht so wirklich....

    composer require phpmailer/phpmailer
    

    Wegen Ahnungslosigkeit, habe ich dann das entsprechende Verzeichnis kopiert. Gut, das haben wir jetzt erst mal.

    Test-Code

     <?php
     // Import PHPMailer classes into the global namespace
     // These must be at the top of your script, not inside a function
     use PHPMailer\PHPMailer\PHPMailer;
     use PHPMailer\PHPMailer\Exception;
     
     
     require __DIR__ . '../../vendor/phpmailer/phpmailer/src/Exception.php';
     require __DIR__ . '../../vendor/phpmailer/phpmailer/src/PHPMailer.php';
     require __DIR__ . '../../vendor/phpmailer/phpmailer/src/SMTP.php';
     
     
     $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
     try {
         //Server settings
         $mail->SMTPDebug = 2;                                 // Enable verbose debug output
         $mail->isSMTP();                                      // Set mailer to use SMTP
         $mail->Host = 'xxxx.de;xxxxx.de';  // Specify main and backup SMTP servers
         $mail->SMTPAuth = true;                               // Enable SMTP authentication
         $mail->Username = 'USER';                 // SMTP username
         $mail->Password = 'PASSWORD';                           // SMTP password
         $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
         $mail->Port = 587;                                    // TCP port to connect to
     
         //Recipients
         $mail->CharSet = 'utf-8'; 
         $mail->setFrom('webmaster@domain.de', 'Domain_Name');
         $mail->addAddress('EMail_Addresse', 'Name');     // Add a recipient
         //$mail->addAddress('test@example.com');               // Name is optional
         $mail->addReplyTo('webmaster@domain.de', 'Name');
         //$mail->addCC('cc@example.com');
         //$mail->addBCC('bcc@example.com');
     
         //Attachments
         $mail->addAttachment('test.jpg');         // Add attachments
         //$mail->addAttachment('test.jpg', 'test.jpg');    // Optional name
     
         //Content
         $mail->isHTML(true);                                  // Set email format to HTML
         $mail->Subject = 'Testmail';
         $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
         $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
     
         $mail->send();
         echo 'Message has been sent';
     } catch (Exception $e) {
         echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
     }
    

    Deutsche Umlaute

    Hatte ich erst nach Einfügen von

    $mail->CharSet = 'utf-8';
    

  • PHP - ChatGPT

    PHP
    1
    0 Stimmen
    1 Beiträge
    63 Aufrufe
    Niemand hat geantwortet
  • PHP Webseite lokal einhängen mit sshfs

    PHP
    1
    0 Stimmen
    1 Beiträge
    39 Aufrufe
    Niemand hat geantwortet
  • Anhänge mit dem PHPMailer

    PHP
    3
    1 Stimmen
    3 Beiträge
    134 Aufrufe
    FrankMF

    @bofh73 Prima, das Du das Problem selber lösen konntest. Prima ist immer ein kleiner Codeschnipsel, damit auch andere Leser was von deinen Beiträgen haben.

  • PHP Installation

    Angeheftet PHP
    3
    0 Stimmen
    3 Beiträge
    517 Aufrufe
    FrankMF

    Falls jemand auch die Warnung in Joomla! bezüglich der php Version 7.4 loswerden möchte, installiert kein php8.1. Damit habe ich eine dicke Fehlermeldung. Es müssen wohl sämtliche Erweiterungen und Templates 8.1 unterstützen, was wohl derzeit noch nicht der Fall ist. Nehmt 8.0, das läuft bei mir aktuell.

    apt install php8.0-common php8.0-mysql php8.0-opcache php8.0-readline php8.0-xml php8.0-xsl php8.0-zip apt install php8.0-cli php8.0-curl php8.0-gd php8.0-intl php8.0-mbstring php8.0-redis apt install php8.0-bcmath php8.0-gmp php8.0-imagick apt install php8.0-fpm
  • Yubikey als 2FA

    PHP
    3
    0 Stimmen
    3 Beiträge
    256 Aufrufe
    FrankMF

    Die ersten 12 Stellen eines Yubikeys sind immer gleich. Diese 12 Stellen speichern wir in einer Datenbank.

    $otp = substr ($otpKey, 0, 12);

    In der Datenbank speichern.

    //SQL $statement = $pdo->prepare("UPDATE users SET otpKey = :otpKey_neu WHERE id = :id"); $statement->execute(array('otpKey_neu' => $otp, 'id' => $userid)); //Überwachung auf Erfolg if ($statement->execute()) { // DB Eintrag erfolgreich geschrieben echo "YubiKey Passwort erfolgreich gespeichert!"; } else { echo "Datenbank Fehler! Bitte informieren Sie den Administrator."; }

    Ich hoffe, es hilft dem ein oder anderen sich mit diesem Thema etwas zu beschäftigen.

  • Wichtige Info

    Angeheftet PHP
    1
    0 Stimmen
    1 Beiträge
    195 Aufrufe
    Niemand hat geantwortet
  • Geo Loacation

    PHP
    1
    0 Stimmen
    1 Beiträge
    286 Aufrufe
    Niemand hat geantwortet
  • Wichtige Links zum Coden

    PHP
    1
    0 Stimmen
    1 Beiträge
    355 Aufrufe
    Niemand hat geantwortet