I have a php script that should be sending an email when a registration is completed. This works fine where as soon as someone registered the email is sent and I receive it. However, I have noticed that sometimes I receive the same email about an hour afterwards. Sometimes it even suddenly sends me an email for a registration that was received weeks ago.
$key=$_GET[key];
if(isset($key) || !empty($key)){
$query1=mysql_query("SELECT * FROM registration WHERE value='$key'");
while($question_list = mysql_fetch_array($query1)){
$num_questions=mysql_num_rows($query1);
$title= $question_list['title'];
$firstname=$question_list['firstname'];
$lastname=$question_list['familyname'];
$dateofbirth=$question_list['dob'];
$gender=$question_list['gender'];
$nationality=$question_list['nationality'];
$email=$question_list['email'];
$to = "userregistration#yahoo.com";
$subject = "Registration";
$message = "Hello! Registration, see below."."\n";
$message.="\n";
$message.="Title: ";
$message.=$title."\n";
$message.="First Name: ";
$message.=$firstname."\n";
$message.="Last Name: ";
$message.=$lastname."\n";
$message.="Gender: ";
$message.=$gender."\n";
$message.="Date of Birth: ";
$message.=$dateofbirth."\n";
$message.="Nationality: ";
$message.=$nationality."\n";
$message.="Email Address: ";
$message.=$email."\n";
$message.="Telephone: ";
$message.=$telephone."\n";
$from = "registration#yahoo.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
}
Change your sql query to
"SELECT * FROM registration WHERE value='$key' LIMIT 0,1"
so that it will send mail only once
in you question list if you are getting 2 records from the table then you will end up sending a single mail twice.
Related
Im trying to get an email to send from my php page to an email address that is set.
The email is being sent and received at the expected email address. But the contents within the email are not as expected. I got the code from watching a tutorial on youtube.
However when looking at the email is displays exactly as the code below, doesn't give me the values behind the variables e.g $name shows up in the email as $name
Any ideas?
The code im using is;
<?php
require_once 'header.php';
$to = 'emailaddress ';
$subject = 'CSG';
$name = $_POST['name'];
$email = $_POST['emailaddress'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi $name, You have recently requested a notification of your password on the Coleg Sir Gar Loan Syste site.
From $name
EMAIL;
$header = '$email';
if ($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Email Sent';
}
?>
Firstly, variables do not get parsed inside single quotes, that's why you're seeing $email rather than the email itself inside the email body.
So change $header = '$email'; to either $header = "$email"; or remove the quotes entirely.
I.e.: $header = $email;
Then the header is failing you. It expects to be a From: (email address) - The "From" in your mail will come back as your server's name rather than the (intended) email address from the person sending it.
Consult the manual:
http://php.net/manual/en/function.mail.php
Sidenote about your heredoc.
Even though mail is going out, you still have a trailing space in your opening identifier:
$body = <<<EMAIL
and that may throw a Parse error: syntax error, unexpected '<<' (T_SL) error.
Error reporting http://php.net/manual/en/function.error-reporting.php
Testing this came back as:
email#example.com
Hi Fred, You have recently requested a notification of your password on the Coleg Sir Gar Loan Syste site.
From Fred
and the "From:" as default#cpanel.example.com rather than whoever#example_mailer.xxx.
As noted in comments by dieend, you can try bracing the variables {$var}, however with or without them, produced the same results for me.
If that still doesn't work, then it may be caused by the trailing space in your opening identifier; you need to remove it.
Copy/paste exactly as shown:
$body = <<< EMAIL
Hi {$name}, You have recently requested a notification of your password on the Coleg Sir Gar Loan Syste site.
From {$name} - {$email}
EMAIL;
$header = "From:" . $email; // Now you have a valid From
if ($_POST){
mail($to, $subject, $body, $header);
echo $feedback = 'Email Sent';
}
Final notes:
If that still doesn't solve the question, then I for one am unable to reproduce.
I have created a registration and after successful registration user get a email about login details(this happens when user clicks submit button).But i have stuck with a sending another email automatically to the same user after 5 minutes and after 20 days user have registered.in the mysql database registration time saved as Time_created.(timestamp).[2016-04-26 10:25:30].what is the possible way to do this.
Here is my code to send email from form this works correctly.
$r = $_GET['rid'];
$aaaa= mysql_query("SELECT email FROM gotest WHERE ID= '$r'");
$bbbb = mysql_fetch_array($aaaa);
$email = $bbbb['email'];
$to = $email;
$subject = ' Site| login ';
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials.
------------------------
Username: '.$name.'
Password: '.$pass.'
------------------------ ';
$headers .= 'From:noreply#xxx.net' . "\r\n";
$headers .= 'Bcc:zzz#xxx.net' ."\r\n";
mail($to, $subject, $message, $headers);
At the time of registration, add mail send date & set no_of_email_send=1. Set a cron which will check whether mail_send_date + 5 mints > now() & no_of_email_send == 1.If this condition satisfy, then send 2nd email & update mail send date & set no_of_email_send=2. If no_of_email_send == 2 then check mail send date + 20days > now() then send 3rd email & update mail send date & set no_of_email_send=3 You can do the validation using single query also.
I am trying to send an email for multiple addresses that are retrieved from db
while($row = mysql_fetch_assoc($qry9)) {
$email=$row["email"];
$subject = "Testing";
$headers = "From: test#gmail.com \r\n";
$message='New Event Registered';
mail($email,$subject,$message,$headers);
}
In this given like $email="nandha181#gmail.com" is working properly but email from database is not working .I am also checking the email from the database query works correctly.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have a PHP website wherein users fill in their registration details and an email goes to them with a link to activate their account. The problem is that sometimes the activation email goes and sometimes it doesnt. I want to make sure that after every registration the activation link email goes to the subscriber to activate his account. Right now there is no way to track this until the user tells us. To solve this I also want to get a copy of that email on my email address so that it acts as additional confirmation.
Here is the current code and any help to solve this would be highly appreciated -
$qq = "select * from quiz_tmpreg where id='".$_SESSION['uid']."'";
$ex = mysqli_query($dbcon, $qq);
$trp = mysqli_fetch_array($ex);
$ToEmail = $trp['email'];
$EmailSubject = "Registration Details";
$mailheader = "From: "."orders#company.com"."\r\n";
$mailheader .= "Reply-To: ".'orders#company.com'."\r\n";
$mailheader .= "Content-type: text/html; charset=utf-8\r\n";
$MESSAGE_BODY = " User Name :- " .$trp['uname']. ",<br>";
$MESSAGE_BODY .= " Password :- " .$trp['pass']. ",<br>";
$MESSAGE_BODY .= " Your Unique ID :- " .$_SESSION['uniq_id']. ",<br>";
$MESSAGE_BODY .= " Activation Link :- http://company.com/confirm.php? encrypt=".$_SESSION['uid']."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader);
unset($_SESSION['uid']);
you can test the result of mail() for any errors. php.net/mail()
as usual, you should present a hint after user's registration, tell him to check the inbox and his spam folder, and to contact you if they didn't receive an email.
you can use timetstamp of registration date to check if any users did sign up but didn't check back via the confirmation link after a certain time. if that happens a lot you can investigate more on that
I want to send an email to multiple recipients using PHP mail() function. The email message is simply a reminder that a membership is due to expire so email addresses will come from MySql database query. There would anywhere from 2-10 at any given time. I found the following code but it generate errors. The problem is not with my query as it generates an accurate recordset. This is the code I have: Hopefully someone can help. By the way, I am very much a novice so need easy straight forward explanation. Thanks in advance:
<?php
$recipients = ("SELECT email FROM tblMembers WHERE search criteria=criteria");
$email_list = $db->query($recipients);
foreach($email_list as $row) {
$to = $row['email'];
$subject = "Membership Renewal";
$headers = "From: Membership Coordinator <membership#myaddress.net>\r\n";
$message = "THIS IS AN AUTOMATED EMAIL. PLEASE DO NOT REPLY""\n""etc, etc, etc";
if ( mail($to,$subject,$headers,$message) ) {
echo "Email was sent successfully";
} else {
echo "Email delivery has failed!";
}
}
?>
As far as I know, then $headers comes after $message, so you should just change the order in mail() and be more aware in future.
Change
$message = "THIS IS AN AUTOMATED EMAIL. PLEASE DO NOT REPLY""\n""etc, etc, etc";
to
$message = "THIS IS AN AUTOMATED EMAIL. PLEASE DO NOT REPLY\netc, etc, etc";
There is the syntax error, because " will end the string. You would need a . to concatenate the next string.
But you could also leave the two " out at this point, becase in a double quoted string, PHP will replace \n by a newline character.