· 7 years ago · Oct 08, 2018, 01:30 PM
1<?php
2header("Content-Type: text/html; charset=utf-8");
3ini_set('display_errors', 1);
4ini_set('error_reporting', E_ALL);
5
6echo 'sendmail<br>';
7echo 'Ð¢ÐµÐºÑƒÑ‰Ð°Ñ Ð²ÐµÑ€ÑÐ¸Ñ PHP: ' . phpversion().'<br>';
8
9
10use PHPMailer\PHPMailer\PHPMailer;
11
12
13require __DIR__ .'/PHPMailer/src/Exception.php';
14require __DIR__ .'/PHPMailer/src/PHPMailer.php';
15require __DIR__ .'/PHPMailer/src/SMTP.php';
16
17
18//Create a new PHPMailer instance
19$mail = new PHPMailer;
20//Tell PHPMailer to use SMTP
21$mail->isSMTP();
22//Enable SMTP debugging
23// 0 = off (for production use)
24// 1 = client messages
25// 2 = client and server messages
26$mail->SMTPDebug = 2;
27//Set the hostname of the mail server
28$mail->Host = 'smtp.gmail.com';
29// use
30// $mail->Host = gethostbyname('smtp.gmail.com');
31// if your network does not support SMTP over IPv6
32//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
33$mail->Port = 587;
34//Set the encryption system to use - ssl (deprecated) or tls
35$mail->SMTPSecure = 'tls';
36//Whether to use SMTP authentication
37$mail->SMTPAuth = true;
38//Username to use for SMTP authentication - use full email address for gmail
39$mail->Username = "******@gmail.com";
40//Password to use for SMTP authentication
41$mail->Password = "*******";
42//Set who the message is to be sent from
43$mail->setFrom('****@gmail.com', 'First Last');
44//Set an alternative reply-to address
45$mail->addReplyTo('****@mail.ru', 'First Last');
46//Set who the message is to be sent to
47$mail->addAddress('****@mail.ru', 'John Doe');
48//Set the subject line
49$mail->Subject = 'PHPMailer GMail SMTP test';
50//Replace the plain text body with one created manually
51$mail->AltBody = 'This is a plain-text message body';
52//send the message, check for errors
53if (!$mail->send()) {
54 echo "Mailer Error: " . $mail->ErrorInfo;
55} else {
56
57 echo "Message sent!";
58 //Section 2: IMAP
59 //Uncomment these to save your message in the 'Sent Mail' folder.
60 #if (save_mail($mail)) {
61 # echo "Message saved!";
62 #}
63}
64
65?>