PHPMailer在本地工作,但不在服务器上工作

时间:2019-12-19 15:43:52

标签: smtp localhost phpmailer

正如标题所述,我无法使我的服务器与PHPMailer一起使用,但与xampp完美配合,我读了很多相关问题,但仍然无法使其工作

require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';

                           use PHPMailer\PHPMailer\PHPMailer;
                           use PHPMailer\PHPMailer\Exception;
                           use PHPMailer\PHPMailer\SMTP;
                            include('/mailer/class.phpmailer.php');
                            $mail = new PHPMailer(true);

                            try {
                                $mail->SMTPDebug = 0;
                                $mail->Host       = 'smtp.gmail.com';
                                $mail->SMTPAuth   = true;
                                $mail->Username   = 'XXXXXXXXXXXXX@gmail.com';
                                $mail->Password   = 'XXXXXXXXXXXXX';                               // SMTP password
                                $mail->SMTPSecure = 'ssl';
                                $mail->Port       = 465;

                                //Recipients
                                $mail->setFrom('xxxxxxxxxxxx@gmail.com', 'xxxx');
                                $mail->addAddress('xxxxxxxxxxxxxx@gmail.com', 'xxxxx'); 

                                // Content
                                $mail->isHTML(true);                                  // Set email format to HTML
                                $mail->Subject = 'Autorizar orden - '.$id.' DNI:'.$nro_doc.'';
                                $mail->Body    = 'zxcxzzxc';
                                $mail->AddAttachment($_FILES['archivo']['tmp_name'], $_FILES['archivo']['name']);

                                $mail->send();
                            } catch (Exception $e) {
                                echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
                            }
                        }

0 个答案:

没有答案