无法调用新的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”] => string(10)“ text / plain” [“ Encoding”] => string(4)“ 8bit” [“ ErrorInfo”] => string(0)“” [“ From”] => string(14)“ root @ localhost“ [” FromName“] =>字符串(9)” Root User“ [” Sender“] =>字符串(0)”“ [” Subject“] =>字符串(0)”“ [” Body“] => string(0)“” [“ [AltBody”] => string(0)“” [“ Ical”] => string(0)“” [“ MIMEBody”:受保护] =>字符串(0)“” [“ MIMEHeader”:受保护] =>字符串(0)“” [“ mailHeader”:受保护] =>字符串(0)“” [“ WordWrap”] => int(0)[“ Mailer”] =>字符串(4)“ mail” [“ Sendmail”] =>字符串(18)“ / usr / sbin / sendmail” [“ UseSendmailOptions”] => bool(true) [“ ConfirmReadingTo”] =>字符串(0)“” [“主机名”] =>字符串(0)“” [“ MessageID”] =>字符串(0)“” [“” MessageDate“] =>字符串(0) “” [“主机”] =>字符串(9)“本地主机” [“端口”] => int(25) “ Helo”] =>字符串(0)“” [“ SMTPSecure”] =>字符串(0)“” [“ SMTPAutoTLS”] => bool(true)[“ SMTPAuth”] => bool(false)[“ SMTPOptions “] =>数组(0){} [”用户名“] =>字符串(0)”“ [[”密码“] =>字符串(0)”“ [” AuthType“] =>字符串(0)”“ [ “ oauth”:protected] => NULL [“ Timeout”] => int(300)[“ dsn”] => string(0)“” [“ SMTPDebug”] => int(0)[“ Debugoutput”] = >字符串(4)“ html” [“ SMTPKeepAlive”] => bool(false)[“ SingleTo”] => bool(false) [“ SingleToArray”:受保护] =>数组(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”] =>数组(0){} [“ DKIM_private”] =>字符串(0)“” [“ [DKIM_private_string”] =>字符串(0)“” [“ action_function”] =>字符串(0) ” “ XMailer”] =>字符串(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] = >数组(0){} “ lastMessageID”:受保护] =>字符串(0)“” [“”消息类型“:受保护] =>字符串(0)”“ [”边界“:受保护] => array(0){} [”语言“:受保护] =>数组(0){} [“ error_count”:受保护] => int(0)[“ sign_cert_file”:受保护] =>字符串(0)“” [“ sign_key_file”:受保护] =>字符串(0) “” [“ sign_extracerts_file”:受保护] =>字符串(0)“” [“ [” sign_key_pass“:受保护] =>字符串(0)”“ [”“”“]”>“保护] =>字符串(0)“”
答案 0 :(得分: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.
答案 1 :(得分:0)
这是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安装存在严重问题,至少我希望看到一些警告记录。
答案 2 :(得分:0)
已修复<- 感谢Synchro ->并感谢Panthers的帮助
添加了使用PHPMailer \ PHPMailer \ SMTP; <-这解决了我的大部分问题,但Synchro并非总是需要
对于使用PHPMailer 6.0.7的工作示例,请查找Synchro的
这是您与上一个问题的重复,标题为“链接”。