2019 Не удалось вызвать новый PHPMailer, который не создает экземпляр PHPMailer версии 6.0.7 - PullRequest
0 голосов
/ 11 июня 2019

Не удалось вызвать новый PHPMailer и не создает экземпляр PHPMailer. Параметр $ mail-> SMTPDebug создает экземпляр stdClass, а затем вызывать несуществующий метод на нем (isSMTP) не удается. Так что все это связано с неудачей создания экземпляра. PHPMailer версии 6.0.7 Live Hosting Service

Я пробовал $ mail = новый stdClass ();
или $ mail = NULL; Это устранение симптомов, но оно не является причиной и приводит к тому, что моя страница отправляет электронное письмо при каждой загрузке.

 <?php 
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require 'PHPMailer/Exception.php';
    require 'PHPMailer/PHPMailer.php';
    require 'PHPMailer/SMTP.php';


    if(isset($_POST[‘submit’]))

    $mail = new PHPMailer(true);

    $mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
    $mail->isSMTP(); 

    $mail->Host = 'mail.email.org'; 
    $mail->SMTPSecure = 'ssl'; <-- Recommend by the hosting service 
    $mail->Port = 465; <-- Recommend by the hosting service <--Hosting Service Docs verify this
    $mail->SMTPAuth = true;
    $mail->Username = 'Mail@email.org';
    $mail->Password = 'Using the correct Password'; 


    $to = 'Mail@email.org'; <-- sending this to myself
    $from = 'Mail@email.org'; <--sending to myself


    $first_name = ((isset($_POST['FirstName']))&&(!is_null($_POST['FirstName'])))? $_POST['FirstName']:'';
    $last_name = ((isset($_POST['LastName']))&&(!is_null($_POST['LastName'])))? $_POST['LastName']:'';
    $email = ((isset($_POST['Email']))&&(!is_null($_POST['Email'])))? $_POST['Email']:'';
    $age = ((isset($_POST['Age']))&&(!is_null($_POST['Age'])))? $_POST['Age']:'';
    $student = ((isset($_POST['Student']))&&(!is_null($_POST['Student'])))? $_POST['Student']:'';
    $agree18 = ((isset($_POST['Agree18']))&&(!is_null($_POST['Agree18'])))? $_POST['Agree18']:'';


   /* Set the mail sender. */
    $mail->setFrom( $to , 'Research');

   /* Add a recipient. */
    $mail->addAddress( $_POST['Email'] , 'Research');
   /* Set the subject. */
    $mail->Subject = 'Learn More about Research Requested';

    $mail->isHTML(TRUE);
    $mail->Body = '<html> "First Name:" . $first_name . " Last Name:" . $last_name .  " Email:". $email . " Age:" . $age . " Student:" . $student . " Agree18:" . $agree18 . ""
</html>';


    $mail->AltBody = ' "First Name:" . $first_name . " Last Name:" . $last_name .  " Email:". $email . " Age:" . $age . " Student:" . $student . " Agree18:" . $agree18 . ""
';  

    if($mail->send()){

      $msg="Your email msg has been send";


    }else{

       $msg="mail msg has not been send"; 
       echo 'Mailer Error: ' . $mail->ErrorInfo;
     }
    ?>

Надеюсь найти решение, почему оно не работает.

Убрал весь мой код, выполнил то, что сказал синхро и получил это:

объект (PHPMailer \ PHPMailer \ PHPMailer) # 1 (74) {["Priority"] => NULL ["CharSet"] ​​=> string (10) "iso-8859-1" ["ContentType"] => string (10) "text / plain" ["Encoding"] => string (4) "8bit" ["ErrorInfo"] => string (0) "" ["From"] => string (14) "root @ localhost "[" FromName "] => string (9)" Root User "[" Sender "] => string (0)" "[" Subject "] => string (0)" "[" Body "] => string (0) "" ["AltBody"] => string (0) "" ["Ical"] => string (0) "" ["MIMEBody": protected] => string (0) "" ["MIMEHeader": protected] => строка (0) "" ["mailHeader": protected] => строка (0) "" ["WordWrap"] => int (0) ["Mailer"] => string (4) "mail" ["Sendmail"] => string (18) "/ usr / sbin / sendmail" ["UseSendmailOptions"] => bool (true) ["ConfirmReadingTo"] => string (0) "" ["Hostname"] => string (0) "" ["MessageID"] => string (0) "" ["MessageDate"] => string (0) "" ["Host"] => string (9) "localhost" ["Port"] => int (25) "Helo"] => string (0) "" ["SMTPSecure"] => string (0) "" ["SMTPAutoTLS"] => bool (true) ["SMTPAuth"] => bool (false) ["SMTPOptions "] => array (0) {} [" Имя пользователя "] => string (0)" "[" Password "] => string (0)" "[" AuthType "] => string (0)" "[ "oauth": protected] => NULL ["Timeout"] => int (300) ["dsn"] => string (0) "" ["SMTPDebug"] => int (0) ["Debugoutput"] = > string (4) "html" ["SMTPKeepAlive"] => bool (false) ["SingleTo"] => bool (false) ["SingleToArray": protected] => array (0) {} ["do_verp"] => bool (false) ["AllowEmpty"] => bool (false) ["DKIM_selector"] => string (0) "" ["DKIM_identity"] => string (0) "" ["DKIM_passphrase"] => string (0) "" ["DKIM_domain"] => string (0) "" ["DKIM_copyHeaderFields"] => bool (true) ["DKIM_extraHeaders"] => array (0) {} ["DKIM_private"] => string (0) "" ["DKIM_private_string"] => string (0) "" ["action_function"] => string (0) «» "XMailer"] => string (0) "" [smtp ": protected] => NULL [" to ": protected] => array (0) {} [" cc ": protected] => array (0) {} ["bcc": protected] => array (0) {} ["ReplyTo": protected] => array (0) {} ["all_recipients": protected] => array (0) {} ["RecipientsQueue ": protected] => array (0) {} [" ReplyToQueue ": protected] => array (0) {} [" attachment ": protected] => array (0) {} [" CustomHeader ": protected] = > array (0) {} "lastMessageID": protected] => string (0) "" ["message_type": protected] => string (0) "" ["border": protected] => array (0) {} ["language": protected ] => array (0) {} ["error_count": protected] => int (0) ["sign_cert_file": protected] => string (0) "" ["sign_key_file": protected] => строка (0) "" ["sign_extracerts_file": protected] => строка (0) "" ["sign_key_pass": protected] => строка (0) "" ["исключения": защищен] => bool (false) ["uniqueid": protected] => string (0) ""

Ответы [ 3 ]

0 голосов
/ 11 июня 2019

Это дубликат вашего предыдущего вопроса с другим названием.

Если у вас есть код, который не работает, сократите его до минимального примера, чтобы исключить возможности двусмысленности и включить подробные, видимые отчеты об ошибках:

use PHPMailer\PHPMailer\PHPMailer;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'PHPMailer/PHPMailer.php';
$mail = new PHPMailer;
var_dump($mail);

Если это не сработает, более сложный скрипт тоже не сработает. Чтобы это не сработало, я подозреваю, что с вашей установкой PHP что-то не так, и, по крайней мере, я ожидаю увидеть в журнале некоторые предупреждения.

0 голосов
/ 13 июня 2019

Исправлено <- <strong> Благодаря Synchro -> и спасибо Panthers за ввод

Добавлено использование PHPMailer \ PHPMailer \ SMTP; <- Это исправило большинство моих проблем, но не всегда требуется для Synchro </p>

Для работы с PHPMailer 6.0.7 ищите Synchro
Это дубликат вашего предыдущего вопроса с другим названием Ссылка.

0 голосов
/ 11 июня 2019

Вы забыли скобку после условия с isset($_POST[...]).

if(isset($_POST['submit'])) {
    //                      ^^
    $mail = new PHPMailer(true);

    $mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
    $mail->isSMTP(); 
    ...
}
// of course, don'f forget to add a closing one too here.
...