問題描述
Gửi email tự động khi tải trang (Send Email Automatically On Page Load)
Is it possible using PHP/HTML/JS that when a user loads a 404 web page it automatically triggers an email to be sent to the web admin notifying them that the page was loaded and how the user got there (what was the page before and what did they click on that page to reach the 404 page.
I dont mean that it opens up the users email client, it should be clean and unobtrusive
參考解法
方法 1:
In order to do do this you would want to create a .php script which will send the email and server the page. Here is a quick walkthrough to set the custom 404 page in Apache.
In order to send the email, you'll want to use PHP's mail()
function. You can read about it here.
After saying this, strongly consider before you do it. I repeat... strongly. Web crawlers and vulnerability scanners are constantly hitting 404 pages... if one happens to hit your site do you really want your admin to get thousands of emails? You would have to find ways to avoid all these cases and only send emails when a 'legitimate' 404 occurs. As well, sending these emails will occupy your server resources, which could make it much easier for a DOS attack to take down your site (overload it by having it send so many emails).
方法 2:
Yes. It is possible. Take a look at php's mail()
.
(by Exhausted、Nick Mitchinson、Aiias)