Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-Type: text/html; charset=utf-8");
- ini_set('display_errors', 1);
- ini_set('error_reporting', E_ALL);
- echo 'sendmail<br>';
- echo 'Текущая версия PHP: ' . phpversion().'<br>';
- use PHPMailer\PHPMailer\PHPMailer;
- require __DIR__ .'/PHPMailer/src/Exception.php';
- require __DIR__ .'/PHPMailer/src/PHPMailer.php';
- require __DIR__ .'/PHPMailer/src/SMTP.php';
- //Create a new PHPMailer instance
- $mail = new PHPMailer;
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 2;
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // if your network does not support SMTP over IPv6
- //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
- $mail->Port = 587;
- //Set the encryption system to use - ssl (deprecated) or tls
- $mail->SMTPSecure = 'tls';
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication - use full email address for gmail
- $mail->Username = "******@gmail.com";
- //Password to use for SMTP authentication
- $mail->Password = "*******";
- //Set who the message is to be sent from
- $mail->setFrom('****@gmail.com', 'First Last');
- //Set an alternative reply-to address
- $mail->addReplyTo('****@mail.ru', 'First Last');
- //Set who the message is to be sent to
- $mail->addAddress('****@mail.ru', 'John Doe');
- //Set the subject line
- $mail->Subject = 'PHPMailer GMail SMTP test';
- //Replace the plain text body with one created manually
- $mail->AltBody = 'This is a plain-text message body';
- //send the message, check for errors
- if (!$mail->send()) {
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- echo "Message sent!";
- //Section 2: IMAP
- //Uncomment these to save your message in the 'Sent Mail' folder.
- #if (save_mail($mail)) {
- # echo "Message saved!";
- #}
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement