【发布时间】:2018-12-05 03:37:35
【问题描述】:
我对 html 文件使用了以下 .htaccess 代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
而且效果很好。
然后我尝试为它们(html 和 php)使用这样的代码:
RewriteEngine on
RewriteBase /
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L]
它没有用。因为我的 html 文件是可以单击的链接,但 php 文件不是链接。它是一个具有 phpmailer 的外部文件,当用户单击发送按钮时,它会发送一封电子邮件。 这是我的 php 文件(contact.php):
<?php
if(isset($_POST['submit'])){
require 'PHPMailer\class.phpmailer.php';
require 'PHPMailer\class.smtp.php';
require 'PHPMailer\PHPMailerAutoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail@gmail.com'; // SMTP username
$mail->Password = 'mypassword9876543210'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($_POST['email']);
$mail->addAddress('mygmail@gmail.com'); // Add a recipient
$mail->addReplyTo($_POST['email']);
//Attachments
// $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
// $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['msg'];
$mail->AltBody = $_POST['subject'];
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
当用户点击此按钮时:
<div class="text-center">
<button type="submit" class="btn btn-start-order" name="submit">Send
Message</button>
</div>
php 文件发送电子邮件,但它也在 url 中显示contact.php。 我怎样才能摆脱 website.com/contact.php 显示并在发送消息后只显示 website.com/contact。对不起,很长的问题。谢谢。
【问题讨论】:
标签: php html .htaccess phpmailer contact-form