Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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
Security PHP Mailer类-保护电子邮件凭据_Security_Email_Phpmailer_Credentials - Fatal编程技术网

Security PHP Mailer类-保护电子邮件凭据

Security PHP Mailer类-保护电子邮件凭据,security,email,phpmailer,credentials,Security,Email,Phpmailer,Credentials,我正在使用php mailer类通过脚本发送电子邮件 结构如下: $mail=新的PHPMailer $mail->IsSMTP(); // Set mailer to use SMTP $mail->Host = 'myserver.com'; // Specify main and backup server $mail->SMTPAuth = true;

我正在使用php mailer类通过脚本发送电子邮件

结构如下:

$mail=新的PHPMailer

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'myserver.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'info@somedomain.com';                            // SMTP username
$mail->Password = 'user123';                           // SMTP password
$mail->SMTPSecure = 'pass123';  
在我看来,在普通视图中使用邮箱凭据有点安全漏洞。所以我想我可以把它们放在web根目录之外的外部文件中。我的问题是,接下来如何为$mail对象分配这些值

我当然不知道如何使用
包括
和/或
要求
。。。这会是一个简单的例子吗

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'myserver.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication

includes '../locationOutsideWebroot/emailCredntials.php';

$mail->SMTPSecure = 'pass123';
然后emailCredentails.php:

<?php
$mail->Username = 'info@somedomain.com';
$mail->Password = 'user123';
?>

这是否足够安全

谢谢


Alan.

我认为您的凭据应该存储在webroot之外的配置文件(INI或JSON)中。因为协议需要原始凭证,所以这是最安全的方法。另外,不要忘记设置对配置文件的正确访问权限

小例子:

<?php

$config = parse_ini_file('/var/app/config.ini', true);

// PHPMailer
$mail->Username = $config['email']['username'];
$mail->Password = $config['email']['password'];

啊,谢谢,这是一个很好的解决方案。使用.ini文件而不是.php文件的意义是什么?通常将应用程序配置信息存储在外部纯文本文件中。MySQL,Apache,随便你说。大多数应用程序都有一个INI文件,甚至有自己的标记语言来存储配置。虽然有些PHP项目也将其存储在带有数组的.PHP文件中,但我发现对于所有参与的人来说,使用一种流行且易于阅读的格式更容易。好吧,这只是一种偏好或风格,从功能和安全性方面来说,它不会有任何区别,对吗?非常感谢…不,因为它们都是纯文本文件。请确保您以适当的权限存储在正确的位置。我对.ini文件的确切含义理解错误,经过一些研究,我发现它具有特定的结构。我现在让它工作并从.ini文件读取。。。。我今天确实学到了一些新东西!