用于订单确认电子邮件的 phpmailer 的安全性
security of phpmailer for order confirmation emails
我想知道使用 phpmailer 发送我的确认电子邮件是安全的。
页面的顺序是这样的:
order_confirmation.php
checkout_process.php(用户在技术上看不到这是发送订单确认信息的页面 to/email 发送给用户并将订单添加到数据库)
checkout_success.php
在 checkout_process 页面上,虽然我正在更改发送电子邮件的方式以使用 phpmailer,因为我们已经看到交换 servers/gmail 帐户正在退回我们的电子邮件。
电子邮件现在可以使用,但我想知道将我们的服务器 info/password 放在 checkout_process.php 页面上是否安全:
try {
//Server settings
$mail->SMTPDebug = false; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.office365.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'email@ourcompany.com'; // SMTP username
$mail->Password = 'our actual password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('email@ourcompany.com', 'company name');
$mail->addAddress($order->customer['email_address'], $order->customer['firstname']); // Add a recipient
$mail->addReplyTo('email@ourcompany.com', 'company');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = EMAIL_TEXT_SUBJECT;
$mail->Body = $email_order;
$mail->AltBody = 'Your order with our company has shipped';
$mail->send();
echo 'order confirmation sent to order#:<br/>';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
为了使用任何邮件服务器,您必须提供秘密凭据,例如您的密码。这样做本身并不会使任何事情变得不安全。如果有人设法侵入您的服务器,他们可以看到这个文件,从而看到密码,但如果它存储在其他地方,他们可以按照与这个文件相同的路径来获取它。 (例如,如果它以加密方式存储在数据库中,则此文件仍需要从黑客也可以访问的地方获取数据库凭据和解密密钥。)
也就是说,如果您的代码位于某种代码存储库中(很可能是),那么不是包含密码的合适位置。除了侵入您的服务器之外,有人现在还可以侵入您的存储库以获取密码。为了避免这个潜在的问题,您的密码应该存储在其他地方,这个文件可以引用。这些天的常见做法是使用 .env
文件来获取此类详细信息,该文件仅存在于服务器上,而不存在于任何存储库中。作为一个附带的好处,它可以很容易地更改凭据(用于您的开发服务器等),而无需触及您的代码。
我想知道使用 phpmailer 发送我的确认电子邮件是安全的。
页面的顺序是这样的:
order_confirmation.php checkout_process.php(用户在技术上看不到这是发送订单确认信息的页面 to/email 发送给用户并将订单添加到数据库) checkout_success.php
在 checkout_process 页面上,虽然我正在更改发送电子邮件的方式以使用 phpmailer,因为我们已经看到交换 servers/gmail 帐户正在退回我们的电子邮件。
电子邮件现在可以使用,但我想知道将我们的服务器 info/password 放在 checkout_process.php 页面上是否安全:
try {
//Server settings
$mail->SMTPDebug = false; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.office365.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'email@ourcompany.com'; // SMTP username
$mail->Password = 'our actual password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('email@ourcompany.com', 'company name');
$mail->addAddress($order->customer['email_address'], $order->customer['firstname']); // Add a recipient
$mail->addReplyTo('email@ourcompany.com', 'company');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = EMAIL_TEXT_SUBJECT;
$mail->Body = $email_order;
$mail->AltBody = 'Your order with our company has shipped';
$mail->send();
echo 'order confirmation sent to order#:<br/>';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
为了使用任何邮件服务器,您必须提供秘密凭据,例如您的密码。这样做本身并不会使任何事情变得不安全。如果有人设法侵入您的服务器,他们可以看到这个文件,从而看到密码,但如果它存储在其他地方,他们可以按照与这个文件相同的路径来获取它。 (例如,如果它以加密方式存储在数据库中,则此文件仍需要从黑客也可以访问的地方获取数据库凭据和解密密钥。)
也就是说,如果您的代码位于某种代码存储库中(很可能是),那么不是包含密码的合适位置。除了侵入您的服务器之外,有人现在还可以侵入您的存储库以获取密码。为了避免这个潜在的问题,您的密码应该存储在其他地方,这个文件可以引用。这些天的常见做法是使用 .env
文件来获取此类详细信息,该文件仅存在于服务器上,而不存在于任何存储库中。作为一个附带的好处,它可以很容易地更改凭据(用于您的开发服务器等),而无需触及您的代码。