├── README.md
├── credential.php
└── index.php
/README.md:
--------------------------------------------------------------------------------
1 | # send-email-using-smtp-phpmailer-localhost
2 | Sending Emails in PHP from localhost with SMTP Using PHPMailer with attachments
3 | Download the library from https://github.com/PHPMailer/PHPMailer/tree/5.2-stable
4 |
5 | Follow the tutorial at:
6 | https://www.youtube.com/watch?v=-B1L0O6S-88
7 | https://www.youtube.com/watch?v=y14b_RW96s0
8 |
--------------------------------------------------------------------------------
/credential.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
Sending Emails in PHP from localhost with SMTP
10 |
Part 3: Using PHPMailer with attachments
11 |
12 | SMTPDebug = 4; // Enable verbose debug output
20 |
21 | $mail->isSMTP(); // Set mailer to use SMTP
22 | $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
23 | $mail->SMTPAuth = true; // Enable SMTP authentication
24 | $mail->Username = EMAIL; // SMTP username
25 | $mail->Password = PASS; // SMTP password
26 | $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
27 | $mail->Port = 587; // TCP port to connect to
28 |
29 | $mail->setFrom(EMAIL, 'Dsmart Tutorials');
30 | $mail->addAddress($_POST['email']); // Add a recipient
31 |
32 | $mail->addReplyTo(EMAIL);
33 | // print_r($_FILES['file']); exit;
34 | for ($i=0; $i < count($_FILES['file']['tmp_name']) ; $i++) {
35 | $mail->addAttachment($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]); // Optional name
36 | }
37 | $mail->isHTML(true); // Set email format to HTML
38 |
39 | $mail->Subject = $_POST['subject'];
40 | $mail->Body = '
This is the HTML message body in bold!
';
41 | $mail->AltBody = $_POST['message'];
42 |
43 | if(!$mail->send()) {
44 | echo 'Message could not be sent.';
45 | echo 'Mailer Error: ' . $mail->ErrorInfo;
46 | } else {
47 | echo 'Message has been sent';
48 | }
49 | }
50 | ?>
51 |
88 |
89 |
90 |
--------------------------------------------------------------------------------