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
    69 Aufrufe
    Niemand hat geantwortet
  • Anhänge mit dem PHPMailer

    PHP
    3
    1 Stimmen
    3 Beiträge
    137 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 Data Objects

    Linux
    4
    0 Stimmen
    4 Beiträge
    272 Aufrufe
    FrankMF
    Datensatz löschen

    Voraussetzung ist, das man die ID des zu löschenden Eintrages kennt.

    $statement = $pdo->prepare("DELETE FROM feinstaub WHERE id = ?"); $statement->execute(array($id)); if ($statement->execute()) { echo "Der DB-Eintrag wurde erfolgreich gelöscht!"; } else { echo "Bitte den Administrator informieren!"; }
  • Yubikey als 2FA

    PHP
    3
    0 Stimmen
    3 Beiträge
    271 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.

  • Eingabefeld aktivieren

    PHP
    1
    0 Stimmen
    1 Beiträge
    190 Aufrufe
    Niemand hat geantwortet
  • Wichtige Info

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

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

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