Send email using SMTP in the easiest way!
Most basic usage – UPDATED FEB 2020 (working)
Download PHPmailer from github (https://github.com/PHPMailer/PHPMailer)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'phpmailer.php'; require 'smtp.php'; $mail = new PHPMailer(TRUE); try { $mail->Subject = 'Your report'; $mail->Body = 'Hello',<br><br> If you have any questions, please do not hesitate to contact us. <br>'; $mail->isSMTP(); /* 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 = 'jeff@gmail.com'; /* SMTP authentication password. */ $mail->Password = 'YOURPASSWORD'; /* Set the SMTP port. */ $mail->Port = 587; $mail->isHTML(true); // xxxxxxxxxxxx ADD ATTACHMENT $mail->addAttachment('mini1.gif'); $mail->addAttachment('images/mini2.gif'); //send the message, check for errors if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } } catch (Exception $e) { echo $e->errorMessage(); } catch (\Exception $e) { echo $e->getMessage(); } ?> |
And with attachments
1 2 3 |