2019 无法调用不创建 PHPMailer 版本 6.0.7 实例的新 PHPMailer
2019 Failed to call to new PHPMailer that does not create an instance of PHPMailer Version 6.0.7
无法调用新的 PHPMailer,也没有创建 PHPMailer 的实例。 $mail->SMTPDebug 的设置创建了一个 stdClass 实例,然后对其调用不存在的方法 (isSMTP) 失败。所以这一切都归结为实例创建失败。 PHPMailer 版本 6.0.7 实时托管服务
我试过 $mail = new 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;
}
?>
希望找到失败原因的解决方案。
删除了我所有的代码,执行了同步说明的内容并得到了这个:
object(PHPMailer\PHPMailer\PHPMailer)#1 (74) { ["Priority"]=> NULL ["CharSet"]=> string(10) "iso-8859-1" ["ContentType"]=> 字符串(10) "text/plain" ["Encoding"]=> 字符串(4) "8bit" ["ErrorInfo"]=> 字符串(0) "" ["From"]=> 字符串(14) "root@localhost" ["FromName"]=> 字符串(9) "Root User" ["Sender"]=> 字符串(0) "" ["Subject"]=> 字符串(0) "" ["Body"]=> 字符串(0) "" ["AltBody"]=> 字符串(0) "" ["Ical"]= > 字符串(0)“”
["MIMEBody":protected]=> string(0) "" ["MIMEHeader":protected]=> string(0) "" ["mailHeader":protected]=> string(0) " " ["WordWrap"]=> int(0) ["Mailer"]=> string(4) "mail" ["Sendmail"]=> string(18) "/usr/sbin/sendmail" ["UseSendmailOptions"]=> bool(true) ["ConfirmReadingTo"]=> string(0) "" ["Hostname"]=> string(0) "" ["MessageID"]=> 字符串(0) "" ["MessageDate"]=> 字符串(0) "" ["Host"]=> 字符串(9) "localhost" ["Port"] => 整数(25)
"Helo"]=> 字符串(0) "" ["SMTPSecure"]=> 字符串(0) "" ["SMTPAutoTLS"]=> 布尔值(真) ["SMTPAuth"]= > bool(false) ["SMTPOptions"]=> array(0) { } ["Username"]=> 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"]=> 布尔值(假)
["SingleToArray":protected]=> array(0) { } ["do_verp"]=> bool(false) ["AllowEmpty"]=> bool(false) ["DKIM_selector"] =>字符串(0)“”["DKIM_identity"]=>字符串(0)“”["DKIM_passphrase"]=>字符串(0)“”["DKIM_domain"]=>字符串(0 ) "" ["DKIM_copyHeaderFields"]=> bool(true) ["DKIM_extraHeaders"]=> array(0) { } ["DKIM_private"]=> string(0) "" ["DKIM_private_string"]=>字符串(0)“”["action_function"]=>字符串(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) "" ["boundary":protected]=> array(0) { } ["language":protected]=> array(0) { } ["error_count":protected]=> int(0) ["sign_cert_file":protected]=> string(0) "" [ "sign_key_file":protected]=> string(0) "" ["sign_extracerts_file":protected]=> string(0) "" ["sign_key_pass":protected]=> string(0) "" ["exceptions":protected]=> bool(false) ["uniqueid":protected]=> string(0) ""
您忘记了 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.
这是 your previous question 的副本,但标题不同。
当您有不起作用的代码时,将其缩减为最小的示例,以便您排除歧义的机会,并启用详细、可见的错误报告:
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 安装存在严重错误,至少我希望看到一些警告记录。
已修复 <-- 感谢 Synchro --> & 感谢 Panthers 的输入
添加使用PHPMailer\PHPMailer\SMTP; <- 这解决了我的大部分问题,但并非每个 Synchro 都需要
对于 PHPMailer 6.0.7 的工作示例,请查找 Synchro 的
这是您之前问题的副本,但标题不同 Link。
无法调用新的 PHPMailer,也没有创建 PHPMailer 的实例。 $mail->SMTPDebug 的设置创建了一个 stdClass 实例,然后对其调用不存在的方法 (isSMTP) 失败。所以这一切都归结为实例创建失败。 PHPMailer 版本 6.0.7 实时托管服务
我试过 $mail = new 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;
}
?>
希望找到失败原因的解决方案。
删除了我所有的代码,执行了同步说明的内容并得到了这个:
object(PHPMailer\PHPMailer\PHPMailer)#1 (74) { ["Priority"]=> NULL ["CharSet"]=> string(10) "iso-8859-1" ["ContentType"]=> 字符串(10) "text/plain" ["Encoding"]=> 字符串(4) "8bit" ["ErrorInfo"]=> 字符串(0) "" ["From"]=> 字符串(14) "root@localhost" ["FromName"]=> 字符串(9) "Root User" ["Sender"]=> 字符串(0) "" ["Subject"]=> 字符串(0) "" ["Body"]=> 字符串(0) "" ["AltBody"]=> 字符串(0) "" ["Ical"]= > 字符串(0)“” ["MIMEBody":protected]=> string(0) "" ["MIMEHeader":protected]=> string(0) "" ["mailHeader":protected]=> string(0) " " ["WordWrap"]=> int(0) ["Mailer"]=> string(4) "mail" ["Sendmail"]=> string(18) "/usr/sbin/sendmail" ["UseSendmailOptions"]=> bool(true) ["ConfirmReadingTo"]=> string(0) "" ["Hostname"]=> string(0) "" ["MessageID"]=> 字符串(0) "" ["MessageDate"]=> 字符串(0) "" ["Host"]=> 字符串(9) "localhost" ["Port"] => 整数(25) "Helo"]=> 字符串(0) "" ["SMTPSecure"]=> 字符串(0) "" ["SMTPAutoTLS"]=> 布尔值(真) ["SMTPAuth"]= > bool(false) ["SMTPOptions"]=> array(0) { } ["Username"]=> 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"]=> 布尔值(假) ["SingleToArray":protected]=> array(0) { } ["do_verp"]=> bool(false) ["AllowEmpty"]=> bool(false) ["DKIM_selector"] =>字符串(0)“”["DKIM_identity"]=>字符串(0)“”["DKIM_passphrase"]=>字符串(0)“”["DKIM_domain"]=>字符串(0 ) "" ["DKIM_copyHeaderFields"]=> bool(true) ["DKIM_extraHeaders"]=> array(0) { } ["DKIM_private"]=> string(0) "" ["DKIM_private_string"]=>字符串(0)“”["action_function"]=>字符串(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) "" ["boundary":protected]=> array(0) { } ["language":protected]=> array(0) { } ["error_count":protected]=> int(0) ["sign_cert_file":protected]=> string(0) "" [ "sign_key_file":protected]=> string(0) "" ["sign_extracerts_file":protected]=> string(0) "" ["sign_key_pass":protected]=> string(0) "" ["exceptions":protected]=> bool(false) ["uniqueid":protected]=> string(0) ""
您忘记了 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.
这是 your previous question 的副本,但标题不同。
当您有不起作用的代码时,将其缩减为最小的示例,以便您排除歧义的机会,并启用详细、可见的错误报告:
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 安装存在严重错误,至少我希望看到一些警告记录。
已修复 <-- 感谢 Synchro --> & 感谢 Panthers 的输入
添加使用PHPMailer\PHPMailer\SMTP; <- 这解决了我的大部分问题,但并非每个 Synchro 都需要
对于 PHPMailer 6.0.7 的工作示例,请查找 Synchro 的
这是您之前问题的副本,但标题不同 Link。