How to use PHPMailer without composer?

前端 未结 2 632
清酒与你
清酒与你 2021-02-05 20:25

I\'d like to use the latest PHPMailer library with require_once() instead of messing around with Composer. I\'d like a pure xcopy deployment with minimal fuss.

相关标签:
2条回答
  • 2021-02-05 20:48

    Here's the full working example (though you see a few variables that must be defined and set):

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    
    require 'src/Exception.php';
    require 'src/PHPMailer.php';
    require 'src/SMTP.php';
    
    $mail = new PHPMailer;
    $mail->isSMTP(); 
    $mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
    $mail->Host = "smtp.gmail.com"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
    $mail->Port = 587; // TLS only
    $mail->SMTPSecure = 'tls'; // ssl is depracated
    $mail->SMTPAuth = true;
    $mail->Username = $smtpUsername;
    $mail->Password = $smtpPassword;
    $mail->setFrom($emailFrom, $emailFromName);
    $mail->addAddress($emailTo, $emailToName);
    $mail->Subject = 'PHPMailer GMail SMTP test';
    $mail->msgHTML("test body"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
    $mail->AltBody = 'HTML messaging not supported';
    // $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
    
    if(!$mail->send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }else{
        echo "Message sent!";
    }
    
    0 讨论(0)
  • 2021-02-05 20:56

    This worked for me, I also downloaded phpmailer from this address

    https://sourceforge.net/projects/phpmailer/

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    use PHPMailer\PHPMailer\SMTP;
    
    require '/source/PHPMailer2/src/Exception.php';
    require '/source/PHPMailer2/src/PHPMailer.php';
    require '/source/PHPMailer2/src/SMTP.php';
    
    0 讨论(0)
提交回复
热议问题