How to configure XAMPP to send mail from localhost?

后端 未结 11 2492
梦如初夏
梦如初夏 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条回答
  •  悲哀的现实
    2020-11-21 05:46

    You have to configure SMTP on your server. You can use G Suite SMTP by Google for free:

    IsSMTP(); // telling the class to use SMTP
        $mail->SMTPAuth = true; // enable SMTP authentication
        $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
        $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
        $mail->Port = 465; // set the SMTP port for the GMAIL server
        $mail->Username = "your-gmail-account@gmail.com"; // GMAIL username
        $mail->Password = "your-gmail-password"; // GMAIL password
    }
    
    // Typical mail data
    $mail->AddAddress($email, $name);
    $mail->SetFrom($email_from, $name_from);
    $mail->Subject = "My Subject";
    $mail->Body = "Mail contents";
    
    try{
        $mail->Send();
        echo "Success!";
    } catch(Exception $e){
        // Something went bad
        echo "Fail :(";
    }
    
    ?>
    

    Read more about PHPMailer here.

提交回复
热议问题