How to configure XAMPP to send mail from localhost?

后端 未结 11 2512
梦如初夏
梦如初夏 2020-11-21 05:17

I am trying to send mail from localhost. but i am unable to send the mail from localhost so can anybody tell me that how to reconfigure my xampp to send mail from localhost

11条回答
  •  猫巷女王i
    2020-11-21 05:51

    I tried many ways to send a mail from XAMPP Localhost, but since XAMPP hasn't SSL Certificate, my email request blocked by Gmail or similar SMTP Service providers.

    Then I used MailHog for local smtp server, what you need to do is just run it. localhost:1025 is for smtp server, localhost:8025 is for mail server, where you can check the emails you sent.

    here is my code:

        require_once "src/PHPMailer.php";
        require_once "src/SMTP.php";
        require_once "src/Exception.php";
    
        $mail = new PHPMailer\PHPMailer\PHPMailer();
    
          //Server settings
        $mail->SMTPDebug = 3;                      // Enable verbose debug output
        $mail->isSMTP();                                            // Send using SMTP
        $mail->Host       = 'localhost';                    // Set the SMTP server to send through
        $mail->Port       = 1025;                                    // TCP port to connect to
        // $mail->Username   = '';                     // SMTP username
        // $mail->Password   = '';                               // SMTP password
        // $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        // $mail->SMTPSecure = 'tls';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
    
        //Recipients
        $mail->setFrom('testtoo@testto.com', 'Mailer');
        $mail->addAddress('testtoo@webbamail.com', 'Joe User');     // Add a recipient
    
        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body in bold!';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Message sent!";
        }
    

    MailHog Github Repository link

提交回复
热议问题