gpt4 book ai didi

php - PHP的mail()函数已经加密了吗?

转载 作者:行者123 更新时间:2023-12-05 03:14:26 24 4
gpt4 key购买 nike

请有人告诉我 PHP 的 mail() 函数是否已经加密,或者我必须自己加密它,我想确保电子邮件的安全传输。

最佳答案

要在 mail() 中使用 SSL 或 TLS,您必须配置“php.ini”(需要在您的服务器上使用 SSL):

http://www.php.net/manual/en/mail.configuration.php

SMTP = YOUR_SERVER
smtp_port = SMTP_SECURE_PORT
sendmail_from = SEND_MAIL_FROM
sendmail_path = SEND_MAIL_APP

但是如果你换了你的服务器,你必须重新做,所以我建议不要使用mail()使用SMTP,有现成的类,见:

PHPMailer 下载:https://github.com/PHPMailer/PHPMailer

使用 TLS 的 PHPMailer 示例:

<?php
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}

关于php - PHP的mail()函数已经加密了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24559115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com