Skip to content

PHPMailer

Verschoben PHP
1 1 492
  • 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';
    
  • php8.2 secutity update

    PHP php linux
    1
    0 Stimmen
    1 Beiträge
    163 Aufrufe
    Niemand hat geantwortet
  • PHP - ChatGPT

    PHP php linux chatgpt
    1
    2
    0 Stimmen
    1 Beiträge
    152 Aufrufe
    Niemand hat geantwortet
  • PHP Webseite lokal einhängen mit sshfs

    PHP php linux
    1
    2
    0 Stimmen
    1 Beiträge
    83 Aufrufe
    Niemand hat geantwortet
  • PHP Data Objects

    Linux pdo php
    4
    0 Stimmen
    4 Beiträge
    358 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 yubikey php
    3
    1
    0 Stimmen
    3 Beiträge
    424 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.
  • Geo Loacation

    PHP php
    1
    0 Stimmen
    1 Beiträge
    338 Aufrufe
    Niemand hat geantwortet
  • Reload einer PHP Seite verhindern

    PHP php
    1
    0 Stimmen
    1 Beiträge
    815 Aufrufe
    Niemand hat geantwortet
  • PHP Exif Daten aus Bild auslesen

    Verschoben PHP php
    1
    0 Stimmen
    1 Beiträge
    565 Aufrufe
    Niemand hat geantwortet