github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/testdata/TestMailpit/send_email.php (about) 1 <?php 2 3 // Include the Composer autoloader 4 require 'vendor/autoload.php'; 5 6 // Import the PHPMailer class into the global namespace 7 use PHPMailer\PHPMailer\PHPMailer; 8 9 // Create a new PHPMailer instance 10 $mail = new PHPMailer(); 11 12 // Set the mail sender 13 $mail->setFrom('admin@example.com', 'Sender Name'); 14 15 // Add a recipient 16 $mail->addAddress('nobody@example.com', 'Nobody at Example'); 17 18 19 // Set the plain text message body 20 $mail->Body = 'This is a test of Mailpit in DDEV'; 21 22 // Check if a subject was passed as an argument 23 if($argc > 1) { 24 $mail->Subject = $argv[1]; 25 } else { 26 $mail->Subject = 'Test using mailpit'; 27 } 28 29 // Send the message 30 if(!$mail->send()) { 31 echo 'Mailer Error: ' . $mail->ErrorInfo; 32 } else { 33 echo 'Message sent!'; 34 }