Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- //Load Composer's autoloader
- require 'vendor/autoload.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 = '...'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = '...'; // SMTP username
- $mail->Password = '...'; // SMTP password
- $mail->SMTPSecure = '...'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = ...; // TCP port to connect to
- [...] corpo do e-mail [...]
- //Attachments [Arquivo]
- $mail->addAttachment('/var/tmp/file.tar.gz'); # Adiciona arquivo
- $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); # nome opcional
- $mail->send();
- echo 'Message has been sent';
- } catch (Exception $e) {
- echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
- }
Add Comment
Please, Sign In to add comment