Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- require 'phpmailer/src/Exception.php';
- require 'phpmailer/src/PHPMailer.php';
- require 'phpmailer/src/SMTP.php';
- $mail = new PHPMailer(true); // Passing `true` enables exceptions to be thrown when something goes wrong
- try {
- // SERVER SETTINGS
- // $mail->SMTPDebug = 2; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'gustavoalbuquerquebr@gmail.com'; // SMTP username
- $mail->Password = 'password'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587; // TCP port to connect to
- // PEOPLE
- $mail->setFrom('gustavoalbuquerquebr@gmail.com', 'Mailer');
- $mail->addAddress('gustavoalbuquerquebr@outlook.com', 'Recipient');
- $mail->addReplyTo('gustavoalbuquerquebr@gmail.com', 'ReplyTo');
- // $mail->addCC('cc@example.com');
- // $mail->addBCC('bcc@example.com');
- // ATTACHMENTS
- $mail->addAttachment('phpmailer.zip', 'mailer.zip'); // Second paremeter is optional
- // CONTENT
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = 'Here is the subject';
- $mail->Body = 'This is the HTML message body <b>in bold!</b>';
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- $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