Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress插件开发:覆盖默认SMTP_Php_Wordpress_Smtp_Phpmailer - Fatal编程技术网

Php Wordpress插件开发:覆盖默认SMTP

Php Wordpress插件开发:覆盖默认SMTP,php,wordpress,smtp,phpmailer,Php,Wordpress,Smtp,Phpmailer,我想覆盖wordpress提供的默认SMTP服务器设置,并且必须在插件中的多个位置使用相同的SMTP设置来发送邮件 新的SMTP服务器详细信息将由用户通过wp admin上的表单提供 在谷歌上搜索时,我突然出现了,而且 我能想到的可能的解决方案 1.为phpmailer类创建一个全局对象,并在插件中使用它 2.覆盖默认的wordpress SMTP服务器设置 3.将用户输入的设置保存到数据库中,并在创建PHPmailer对象时检索它,无论我在哪里发送邮件 我在上述解决方案中面临的问题是 第一种解

我想覆盖wordpress提供的默认SMTP服务器设置,并且必须在插件中的多个位置使用相同的SMTP设置来发送邮件

新的SMTP服务器详细信息将由用户通过wp admin上的表单提供

在谷歌上搜索时,我突然出现了,而且

我能想到的可能的解决方案
1.为phpmailer类创建一个全局对象,并在插件中使用它
2.覆盖默认的wordpress SMTP服务器设置
3.将用户输入的设置保存到数据库中,并在创建PHPmailer对象时检索它,无论我在哪里发送邮件

我在上述解决方案中面临的问题是

第一种解决方案。我不知道如何实现它
第二个解决方案:我在wordpress codex上找不到任何资源,这可以解释如何覆盖默认smtp设置
第三个解决方案:生产力不够

另外,我正在尝试创建一个独立的插件,因此无法创建对任何第三方插件的依赖。虽然我已经试着浏览了的源代码,但无法理解如何在多个位置使用相同的设置

我正在使用Tom Mcfarlin的Wordpress样板插件(),以创建一个标准的插件文件结构,因此如果有人能向我解释使用样板的解决方案,它将非常有用和高效

编辑:
为了更好地理解,我正在上传文件结构。

这是表格

表单值在class-atf-admin.php中成功检索


我需要在class-atf-admin.php中创建一个全局变量,在这里我将设置从表单接收到的值,并在上图所示的文件中使用它。Mkay,我将在选项1处出现一个裂缝(尽管在phpmailer命名上不是100%)

在主插件文件中,基于


为什么你不能更改Wordpress的SMTP设置?我想通过我的插件更改Wordpress的SMTP设置,如果你能帮助我实现这一点,那将非常有帮助。我在wordpress Codexpress上找不到任何资源请不要链接到旧文档。我已经修改了链接指向当前位置,并对代码进行了一些更新。
<?php    
require_once 'phpmailer/PHPMailerAutoload.php';

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
}