i am messing with my website, then i thought why not add a visitor mail notification to myself.
I added Following Code to my website using
include("visit_mail.php");
but even if my website have 1 visit i receive 20 emails from x-mailer. here is the code of x-mailer
$browser = $_SERVER['HTTP_USER_AGENT'];
$time = date("g.i A l-d F Y", time() + 6*60);
$ip=getenv('REMOTE_ADDR');
$email_me= "me#mydomain.com";
$msg = "\nHey SomeOne Visited Your WebSite\nIP: $ip\nBrowser:$browser\n$time.";
$subject = "Visitor On $site_name";
$headers = 'From: me#mydomain.com' . "\r\n" .
'Reply-To: me#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
'X-Priority: 1\n'.
'Priority: Urgent\n'.
'Importance: high';
$x =mail($email_me, $subject, $msg, $headers);
if($x){echo "";}else{echo "";}
Multiple requests are send when visiting a website, this may cause the script to execute multiple times. You could try adding:
$page = $_SERVER['REQUEST_URI'];
$msg .= 'They visited page: ' . $page;
to check what page they visited.
more details about the user visiting the site can be retrieved with the following: https://www.php.net/manual/en/reserved.variables.server.php
Related
I have a script that sends data to a table in mysql database and now I've wanted to generate an email everytime someone adds new data. It works, but as you may know, it lasts almost 20-30 secs to complete and get the response.
I´ve read that exec function would have been good for executing mail() in a separate file, but at my shared server exec is disabled. Also are disabled these others:
symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,show_source,pcntl_exec
Anybody can show how can I make this posible without blocking webpage until email is sent?
Thankyou!
the mail function looks like this. Is something in it making it slow??
$to = "xxx#gmail.com";
$subject = "xxxxx";
$message = "xxxxxxxxx: \n";
$message .= "\n";
$message .= " $getuser\n";
$message .= "\n";
$headers = 'From: xxxx#gmail.com' . "\r\n" .
'Reply-To: xxx#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headerxs);
I'm sending off a php mail upon submission of this form. I want the page to redirect after submission. The problem I'm having is the form submits, the old page reloads, then the redirection kicks in. Any thoughts on how I can skip the reload and just do the redirect? Code below:
<?php
if(isset($_POST['button_pressed']))
{
$to ='email#email.com';
$subject = 'New Sign Up!';
$message = $_POST['MERGE1'] . ' ' . $_POST['MERGE2'] . ' with the email address ' . $_POST['MERGE0'] . ' has just registered using the Sign Up Now Popup Form';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$url = 'http://www.example.com/?sub=true';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
?>
change the below lines from:
$url = 'http://www.example.com/?sub=true';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
to:
$url = 'http://www.example.com/?sub=true';
header("Location:" . $url)
The header() function sends a raw HTTP header to a client.
header('Location: http://www.example.com/?sub=true');
I have one php file which sends me an email every time it's loaded. There is no user input fields, it is not contact form or any other form. It's just a redirect php file and I want to receive email each time it is loaded. I have included following php mail function in it and wonder if there are any security issues with it (since there are no user input fields I am hoping I can leave it like this):
$to = 'myemail#gmail.com';
$subject = 'the file is loaded';
$message = 'the file loaded, check it out';
$headers = 'From: webmaster#mywebsite.com' . "\r\n" .
'Reply-To: webmaster#mywebsite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
From functionality perspective this is perfectly safe. Your e-mail can't be altered.
However, if one person decides to troll you, he can send you an incredible amount of e-mails in a very short time. Your host or ISP will get pissed over this.
You can avoid this with queueing. Get a database or a file, save the amount of times the page is called and when the last e-mail is sent.
If the script is called AND the last sent e-mail is x minutes ago, you can send yourself a message that the page has been called x times. Then, you just empty the database and restart counting :)
Here's a script to get your started (haven't tested)
// Duration in seconds
$duration = 60 * 15;
$now = time();
$file = 'tmp.json';
$json = json_decode(file_get_contents($file));
array_push($json['calls'], $now);
// It appears it's time to send the content
if($json['sent'] + $duration > $now) {
$to = 'myemail#gmail.com';
$subject = 'the file is loaded';
$headers = 'From: webmaster#mywebsite.com' . "\r\n" .
'Reply-To: webmaster#mywebsite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '';
// Generate message
foreach($json['calls'] as $c) {
$message .= sprintf("File loaded at: %s\r\n", date('r', $c));
}
if(mail($to, $subject, $message, $headers)) {
// Reset the file but ONLY if the mail was sent
file_put_contents($file, json_encode(array(
'calls' => array(),
'sent' => $now
)));
}
} else {
file_put_contents($file, json_encode($json));
}
What security issues may there be with an email that has static content which you posses full control over. Anyway I believe it would be better if you just kept track of your file loads in a local file or a database. Good luck! :P
i m using a php form for sending the contact email from my website. the code is ok and working fine on one website but not working in second website. both website having difference server space and hosting. Not showing any error on page
code is below :
<?php
$name = $_REQUEST['rohini_name'] ;
$contact = $_REQUEST['rohini_contact'] ;
$email = $_REQUEST['rohini_email'] ;
$remark = $_REQUEST['rohini_message'] ;
$MailTxt = "Following are Details" . "\r\n" .
"============================" . "\r\n" .
"Name : " . $name . "\r\n" .
"Mobile : " . $contact . "\r\n" .
"Email : " . $email . "\r\n" .
"Remark : " . $remark . "\r\n";
$to = "ballu9868#gmail.com";
$subject = "Enquiry from rohiniseeds.com";
$headers = "From: www.rohiniseeds.com";
mail($to,$subject,$MailTxt,$headers);
?>
Please ask your hosting to make sure that mail funstion is supported.
Try adding an IF statement around the mail($to,$subject,$MailTxt,$headers) function as follows:
if(mail($to,$subject,$MailTxt,$headers)){
echo 'Success!';
} else {
echo 'Error!';
}
If it says Success then you know that it's being sent by the server, and the problem is when it's trying to hit the inbox. If it says error, then the problem related to the server.
Also, please use email#rohiniseeds.com in the from header, which is a valid email address, instead of the URL of the website.
Please try this
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
I'm using PHP's mail() function and noticing that my mail is being shown from being sent by 'My Website' in my inbox, but when I click on the actual email it shows it being sent from mywebsite#sitename.localdomain.
Ideally I'd like to have it say being sent from 'My Website', but the reply email being 'no-reply#mywebsite.com', and not to have it say anything about #sitename.localdomain.
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website' . "\r\n" .
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
Is this an issue that I need to fix in Apache, or can I modify the headers within PHP?
Try this:
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website <no-reply#mywebsite.com>' . "\r\n" . // <- change your email here
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
The Question and Answer #1 contains a serious security vulnerability -
$to = trim(strtolower($_POST['to']));
Will allow an attacker to use your website to email arbitrary spam and your site will be blocked from most search engines.
See
https://www.owasp.org/index.php/Top_10_2010-A1
My recommendation is to
Sanitize the to and from fields
Never ever ever copy the message in the post to the output unless carefully sanitized.