MAILER NEEDED.

Teacher

Professional
Messages
2,674
Reputation
9
Reaction score
660
Points
113
Sane instructions for PHPMailer - Sending e-mails and files to e-mail”
PHPMailer has been updated and the instructions for the previous version are not relevant, although you can also use the attached files in that instruction. It will work.

A few years have passed, but you still have no way out, and PHPMAILER is the easiest way to send emails from your site to your email address.
Here's what you might end up with. Touch: https://jsfiddle.net/dzLh63oe/

What this manual is about.
This is how to add PHPMailer to your site and send emails with attached files to your email address without reloading the page.
Here you will find instructions for a simpler basic version of the form, without animation and validations in pure JavaScript. You can download a fancy version of the form (the one in the picture) from the link at the end of the article.

1. Download PHPMailer
Go to the site https://github.com/PHPMailer/PHPMailer and download the latest version
1*OQt919Wq94TBLHRXYxyFow.png

At the beginning, click on "Clone or Download”, then on" Download ZIP”
We only need 3 files in the entire archive:
PHPMailer\src\PHPMailer.php
PHPMailer\src\SMTP.php
PHPMailer\src\Exception.php
Everythingaboutelse that is stored on Github is not needed on*yy, you can delete it.

2. Remove all junk from files
You can skip this point. It is optional
Files written by PHPMailer developers contain a huge amount of garbage consisting of comments alone (why?!). The weight of these three files together with the comments is equal to 196kb.After deleting the comments, the weight will be 72kb. Almost 3 times…
I suggest deleting all comments in files using some "PHP minifier". You can use any one, I took it (the first one that came across) http://php-minify.com
  1. Open the file PHPMailer.php
  2. Copy the contents of the file
  3. Insert php-minify into the form on the site and click "COMPRESS”
  4. Save the result to a new file with the same name
Repeat the procedure with all three files.
For clarity, the file Exception.php

1*jbgu6GewZgH6tbMvlj1eIg.png


On the left is the file before compression, on the right it is also after garbage removal

3. Move files to the project
And now we put these 3 files in our project. I created a folder called phpmailer specifically for these files

1*XiuQttyt9XhzX7g3r6BsSg.png


4. Create a configuration file
Creating a file send.php with this content

Here you need to edit these fields for yourself:
// Forming the email
itself$title = "Email title";
$body = "Email itself"// Your mail settings
$mail - >Host = ' smtp.yandex.ru'; / / SMTP server of your mail
$mail - >Username = 'your_login'; >// Login in the mail
$mail->Password = 'Password'; // Password for the mail
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
// Address of the email sender name
$mail->setFrom('[email protected]', 'sender Name');// the Recipient of the email
$mail->addAddress('[email protected]');
$mail->addAddress('[email protected]'); // One more if needed

You don't need to use the password for Yandex.Mail itself, but the “App Password”. In the settings of your mail, whether it's Gmail, Yandex, or Mailru, there is a section “Application Passwords”, where you can specifically create a separate generated password for PHPMailer.
Save this file send.php and we put it in the root of the site
The example shows the settings for Of Yandex. You can use any email address to send it. To change the sending email, for example, to Gmail, you need to change these fields:
$mail->Host = ‘smtp.gmail.com'; > / / SMTP server
$mail - >SMTPSecure = ' ssl’; > / / Encryption
$mail->Port = 465; > / / Port

5. Creating an HTML form
Now let's put this form in the right place on your site
Pay attention to onsubmit. There, the second argument must specify the file name, i.e. send.php.

6. Prescribe JavaScript
Now you just need to place this function somewhere in the code. You can copy it to your script file, which is already included in <head>, <head>, or paste it after the closing tag </body>.

7. Everything (almost)

Your form should look like this:

And in case of success (or failure), you should get a pop-up message from the browser saying “Message sent” or"Error...".

8. Why the error?

This is a very common question, where I confidently can say, 60% of the causes of errors is your hosting 30% of your post, 9% — you incorrectly entered data from the mail, and 1% of the reasons you're a fucking retard who decided to change the code, and then begin to genuinely wonder why nothing works.
To find out what the reason is, you need to uncomment this line of code (remove //):
//$mail->SMTPDebug = 2
Now in the browser, open the console (F12) > "console" tab and send a message. You should have a new line (list) that you need to expand:

1*VzfxoAF261pI7UQVNmtwRQ.png


Reason: Error: authentication failed: Invalid user or password!, in other words, the email data was entered incorrectly.
If these lines are like hieroglyphs for you, and you are sure that there is no error in writing the mail data, then send two messages: one to tech.support for your hosting, the second in those.support for your email with this content:
Hello. I'm trying to configure PHPMailer, but I have an error in the logs:
*HERE YOU REPLACE THESE LINES FROM THE CONSOLE*
After a while, they will respond and emails will start leaving normally.
After that, I strongly recommend that you comment out the line c $mail->SMTPDebug = 2 again

9. Download ready-made files

Clean basic form without fucking: Download
Form with email validation and GSAP animation: Download
Settings for other emails: https://snipp.ru/view/146
This form has a disadvantage: there is no spam protection. You need to enable the captcha separately

Thanks for your attention
And click on the "Palms" (claps) to put a like.
 
Top