This question already has answers here:
Does page reload ever cause post?
(3 answers)
Closed 8 years ago.
can you please tell anybody what is the error this my code. this code working properly but first time i click the send button after send message to my email. but second time i don't need to click the send button only i do refresh my page then message send automatically to my email. what's the problem?
if(isset($_POST['send'])) {
$name = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$interested = $_POST['interested'];
$message = $_POST['message'];
if(!empty($name) && !empty($email) && !empty($message) )
{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Regoora Message Center";
$message1 = "Customer Name :".$name."
Customer Email :".$email."
Customer Phone :".$phone."
Customer interested :".$interested ."
Customer message :".$message." ";
mail("email#example.com",$subject,$message1);
$mess = "Successfully sent your inquiry";
}
else{
$mess = 'We are sorry, but there appears to be a problem with the form you submitted.';
}}
If your code worked properly the first time, it is because it works fine. The second time you just refreshed the page and it sent another email because 'Refresh' will always repeat your last action. If you last action was 'Send Email', refreshing the page will try to resend the email.
What you could do to avoid that is, after sending, click on the address bar (http://localhost/xxxx) and press enter. It will reset the page.
Related
I am New to php . Any help would be greatly appreciated.
My issue is that when user reply to any post with specific id, php sends an email alerting involved users that have previously comment on the post with same id, the problem is if the person has entered 3 reply for that post the user gets 3 emails, Since my database has reply entries from the same user with email for each post multiple times.
This is what is the problem
$to = $row['Email'];
How do I make sure it does not send an email to the user multiple times?
// update data in mysql database
$sql4= "select * from answer WHERE id='$id'";
$result4=mysql_query($sql4);
while($row = mysql_fetch_array($result4))
{
$to = $row[‘email’] ;
// Your subject
$subject="$name Reply on example.com”;
// From
$header="from: Associate <no-reply#example.com>";
// Your message
$message = "$name Reply on example.com\n$comment\nDate and Time=$datetime\nhttps://www.example.com/upload/$img\nfor More Visit https://www.example.com/visit/“;
// send email
$sentmail = mail($to,$subject,$message,$header);
}
Change your query to this: $sql4= "SELECT DISTINCT * FROM answer WHERE id='$id'";
you can add email in array and use array_unique function so your duplicate entry will remove auto.
<?php
$a=array("a"=>"red","b"=>"green","c"=>"red");
print_r(array_unique($a));
?>
I've searched around with no luck here. I created a PHP email form that works great. Now I need to edit the email subject line to pull information from the contact form.
Here's what I'm looking to have as the email subject line:
"You have a $variable inquiry from $variable.
Here's my current code that is giving me an error on the $Subject line:
$EmailFrom = "Contact#xxx.com";
$EmailTo = "ryan#xxx.com";
$Subject = "You have a .$Subj inquiry from .$Name";
$Name = Trim(stripslashes($_POST['sender_name']));
$Email = Trim(stripslashes($_POST['sender_email']));
$Message = Trim(stripslashes($_POST['message']));
$System = Trim(stripslashes($_POST['system']));
$Item = Trim(stripslashes($_POST['item']));
$Subj = Trim(stripslashes($_POST['subj']));
So I have tried adding a <> around the variables in the $Subject. I have also tried with the periods as above, as well as with just the $xxx.
When I send the email, it will send as:
"You have a <> inquiry from <>"
or
"You have a . inquiry from ."
Depending on which characters I have around the $xxx variable.
I know this is probably some stupid error, but can someone hint me at what I need to do to have those variable pulled into the $Subject?
Thanks in advance,
Ryan
You have your variable declarations out of order.
You are using $Name in the first line before you have assigned a value to it. You need to put the lines that give values to $Name and $Subj before the line that uses them.
This question already has answers here:
How to validate an Email in PHP?
(7 answers)
Closed 9 years ago.
I have a newsletter subscribe form on my website and i want it to go to a page that
confirms the user has been signed up. At the moment it just refreshes the page and gives
you a little message where the form box was. Having tested it, it also doesn't care whether
you put the email address in wrongly etc. I would like it so it checks this info and only
submits correct email addresses. The code that is there at the moment is
<?php
// get vars
$email_address = strtolower(trim($_REQUEST['email_address']));
if((strlen($email_address) > 0) && (strpos($email_address, "#")))
{
// add to db
$newsletterQry = db_query("SELECT * FROM newsletter_subscribers WHERE email='" . mysql_real_escape_string($email_address) . "'");
if(db_num_rows($newsletterQry) == 0)
{
// add
db_query("INSERT INTO newsletter_subscribers (email, created) VALUES ('" . mysql_real_escape_string($email_address) . "', NOW())");
}
}
// return back to the index page with confirmation
header("location: ".$_SERVER["HTTP_REFERER"]."?nlMsg=".urlencode("You've been added to the site newsletter."));
exit;
?>
See the solution on How to validate an Email in PHP.
You want to sanitize e-mail addresses using either RegEx, or PHP's built-in filter_var() function.
<?php
$email_address = strtolower(trim($_REQUEST['email_address']));
if (filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
// This email address is valid insert into newsletter
}
I recently made a portfolio website and put it online on 000webhost.com. Today when I logged in, the account was suspended because someone sent more then 70 emails in a minute via my contact form - something that the webhosting does not allow.
I am looking for some way to stop this from hapening again. I used both php and javascript/jquery for form validation.
This is my curent php validation code.
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$message = $_POST["message"];
$to = "fox.team001#gmail.com";
$subject = $firstName . " " . $lastName;
$headers = "From: " .$firstName . " " . $lastName . "\r\nReply-To:" . $email;
if(validateEmail($email)){
#mail($to , $subject , $message , $headers);
}
validate($firstName , $lastName , $email , $message);
function validate ($firstName , $lastName , $email , $message){
if(!empty($firstName) && !empty($lastName) && !empty($email) && !empty($message)){
if(validateEmail($email)){
header("refresh:5; url=http://www.foxteam.net");
}else{
header("refresh:0; url=http://www.foxteam.net/contact.php");
}
}else{
header("refresh:0; url=http://www.foxteam.net/contact.php");
}
}
function validateEmail($email) {
$pattern = "^[A-Za-z0-9_\-\.]+\#[A-Za-z0-9_\-]+\.[A-Za-z0-9]+$";
if(preg_match("/{$pattern}/", $email)) {
return true;
}else{
return false;
}
}
Can anyone tell me how can I stop spammers to send spam emails?
It's very hard to stop spam coming through a contact form completely, however there are a number of methods you can use to reduce it, some of which include:
Use a honeypot - the idea behind this is to have a hidden field on your form with a generic name (e.g. answer), if this field has anything in it, then don't bother sending the email (but still tell the user that the email has been sent) - it is obviously spam as there is no other way the field could have been filled out.
IP limiting - store the user's IP address somewhere and limit the number of emails per minute/hour that each IP address can send.
Word filtering - have a list of words, if any are found then don't send the email (usualy words like viagra, penis, etc).
CAPTCHA, to me, this is a last resort. If you do use one, implement recaptcha, it is by far the best one around. But as I say, use this as a last resort, there are plenty of other methods you can use without annoying the users of your website.
You can use CAPTCHA to block robot spammers
put your if() condition into for loop which contains range 70 and then send email only. if it will over by 70 then put it over else part with some suitable message
Thanks
following is my script for send email inquiry.. the recipient email address was stored in a db called users.. this script will not work properly.. i think the problem is recipient email section.. because when i used a email address instead of $user it will work..
thanx help me
<?php
$refno = $HTTP_POST_VARS['refno'];
$proid = $HTTP_POST_VARS['proid'];
$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$msg = $HTTP_POST_VARS['msg'];
//connect db and find email address related to id
include 'db_connector.php';
$id=$HTTP_POST_VARS['id'];
$query=mysql_query("SELECT user_email FROM users WHERE id='".$id."'");
$cont=mysql_fetch_array($query);
$user=$cont['user_email'];
// recipient name
$recipientname = "'".$name."'";
// recipient email
$recipientemail = $user ;
// subject of the email sent to you
$subject = "Inquiry for your advertisement No. (".$refno.")";
// send an autoresponse to the user?
$autoresponse = "no";
// subject of autoresponse
$autosubject = "Thank you for your inquiry!";
// autoresponse message
$automessage = "Thank you for your inquiry.! We'll get back to you shortly.
";
// END OF NECESSARY MODIFICATIONS
$message = "reference number : $refno
$msg
From $name $email
---";
// send mail and print success message
mail($recipientemail,"$subject","$message","From: $recipientname <$email>");
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
header("Location:index.php");
exit;
?>
First of all, your query is SQL injectable. Never ever pass a variable coming from a POST request directly into an SQL query. Use mysql_real_escape().
As to your bug: it seems that $user does not contain a valid e-mail address. so, the Mysql query is not returning an e-mail address.
Use $_POST rather than $HTTP_POST_VARS.
Switch on error reporting by prepending these two lines to your PHP code:
PHP code:
error_reporting(E_ALL);
ini_set('display_errors','1');
Run your script again. Do you get any notices or warnings?
If not, try to display your query, by adding
die($query);
just before the line that has the mysql_query command, and then run the query manually (e.g. using PhpMyAdmin or MySQL Query Browser) to see if you are actually getting a result that looks like an e-mail address.
Debug your PHP program.
Check out :
If the variables contain the supposed values.
Query is okay and returns result.
Proper header is set with mail function.
etc.
PHP manual have a good example to send mail.
Do not use $HTTP_POST_VARS['name']; it is deprecated use $_POST instead.
hey guys thanx for the help.. i found the error done in my inquiry form.. the id filed hidden outside of the form tag.. therefore the id value will not passed to the sendinq.php. i change it thank now the sendmail option work properly