请有人告诉我,PHP的mail()函数已加密,或者我必须自己加密,我想安全地发送电子邮件。
答案 0 :(得分:1)
要使用带有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';
}
答案 1 :(得分:0)
mail()
功能将使用本地邮件程序(Linux)或连接到标准端口25(Windows)。绝对没有办法:
如果担心安全性(或可靠性),请不惜一切代价避免使用。