Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PHPMailer\PHPMailer\PHPMailer;
- use PHPMailer\PHPMailer\Exception;
- /* Exception class */
- require '\PHPMailer\src\Exception.php';
- /* The Main PHPMailer class */
- require '\PHPMailer\src\PHPMailer.php';
- /* SMTP class */
- require '\PHPMailer\src\SMTP.php';
- $mail = new PHPMailer(TRUE);
- try {
- /* Set the mail sender. */
- $mail->setFrom('sender email', 'person');
- /* Add a recipient. */
- $mail->addAddress('add recipient', 'person');
- /* Set the subject. */
- $mail->Subject = 'Test';
- /* Set the mail message body. */
- $mail->Body = '<html>I am testing PHPMailer and <strong>HTML</strong>.</html>';
- /* SMTP parameters. */
- /* Tells PHPMailer to use SMTP. */
- $mail->isSMTP();
- $mail->SMTPDebug=4;
- /* SMTP server address. */
- $mail->Host = 'smtp.gmail.com';
- /* Use SMTP authentication. */
- $mail->SMTPAuth = TRUE;
- /* Set the encryption system. */
- $mail->SMTPSecure = 'tls';
- /* SMTP authentication username. */
- $mail->Username = 'something@here.com';
- /* SMTP authentication password. */
- $mail->Password = 'something here';
- /* Set the SMTP port. */
- $mail->Port = 587;
- /* Finally send the mail. */
- $mail->send();
- }
- catch (Exception $e)
- {
- /* PHPMailer exception. */
- echo $e->errorMessage();
- }
- catch (\Exception $e)
- {
- /* PHP exception (note the backslash to select the global namespace Exception class). */
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement