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
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 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.
I'm setting up a Magento website and before it goes live I want to set up a under construction page.
I'd like to have people who are interested to subscribe and we'll send them out a email when the shop goes live.
I tried out bunch of these bigger PHP mailing/newsletter systems, but they were way to complicated and time consuming to get into because I need to work on other things.
So I'd like to know is there a easy way to do it myself or is there a script just for this task I haven't found yet? I also searched through few tutorial sites for what I was looking for, but I couldn't find anything useful. I really just need the bare minimum for this.
Thank you in advance, hopefully this question fits to this site.
use this in your page:
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
<button type="submit" class="btn_email">Send</button>
</form>
<!-- End Subscription Form -->
and this for form.php:
<?php
$to = "office#site.com";
$from = "no-reply#site.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
the above script will only send you an email with the new subscription, but you can extend it to do database insertion, subscriber confirmation, etc. And also validate the data in the field where the subscriber enter the email.
Make a simple form that lets users enter a name and email address. Have the email addresses go straight into a database or some other form of storage (could be as simple as a text file).
Then, when ready, write a simple script that will send out an email to all the users in the database.
i have a registration form that allows users to register and become members on my site. So far once they register their details this goes in the database and they get an email sent out to say thanks.
I am trying to duplicate the script so that i can send a different email letting me know when a users registered and have this sent to my email.
I'm trying to do it this way because the email that gets sent out to the user contains a randomly generated md5 hash code that i also need to have sent to me in the email sent to me telling me they've registered.
I've managed to get the two emails to deliver to the correct email accounts. however, the email being sent to me letting me know a user has signed up is also being sent to the user and i don't want it to go to them?
Can anyone suggest where I'm going wrong? Thanks
CODE to send email to user:
<?php
/**
* ShuttleCMS - A basic CMS coded in PHP.
* code generator - Used for allowing a user to generate a code
*
* #author Dan <dan#danbriant.com>
* #version 0.0.1
* #package ShuttleCMS
*/
define('IN_SCRIPT', true);
// Start a session
session_start();
/*
* Generates new code and puts it on database
*/
//Generate a RANDOM MD5 Hash for a code
$random_code=md5(uniqid(rand()));
//Take the first 8 digits and use them as the password we intend to email the user
$emailcode=substr($random_code, 0, 8);
//Encrypt $emailpassword in MD5 format for the database
$registrationcode=($emailcode);
// Make a safe query
$query = sprintf("UPDATE `ptb_registrations` SET `registration_code` = '%s' WHERE email = \"$email\"",
mysql_real_escape_string($registrationcode));
mysql_query($query)or die('Could not update members: ' . mysql_error());
?>
<?php
$subjectconfirm = " Thanks for your Registration";
$headersconfirm = "To: $email\r\n";
$headersconfirm .= "From: siteindex.com <registrations#siteindex>\r\n";
$headersconfirm .= "Content-type: text/html\r\n";
$sep = sha1(date('r', time()));
$bodyconfirm = <<< EOF
(EMAIL BODY)
EOF;
// Finally, send the email
mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm);
?>
Then i'm duplicating the code like this but replacing the to email address. and it sends to my email account fine but it sends both emails to the user and i don't want them getting the email intended for me.
Code to have email sent to me:
<?php
/**
* ShuttleCMS - A basic CMS coded in PHP.
* code generator - Used for allowing a user to generate a code
*
* #author Dan <dan#danbriant.com>
* #version 0.0.1
* #package ShuttleCMS
*/
define('IN_SCRIPT', true);
// Start a session
session_start();
/*
* Generates new code and puts it on database
*/
//Generate a RANDOM MD5 Hash for a code
$random_code=md5(uniqid(rand()));
//Take the first 8 digits and use them as the password we intend to email the user
$emailcode=substr($random_code, 0, 8);
//Encrypt $emailpassword in MD5 format for the database
$registrationcode=($emailcode);
// Make a safe query
$query = sprintf("UPDATE `ptb_registrations` SET `registration_code` = '%s' WHERE email = \"$email\"",
mysql_real_escape_string($registrationcode));
mysql_query($query)or die('Could not update members: ' . mysql_error());
?>
<?php
$subjectconfirm = " Thanks for your Registration";
$headersconfirm = "To: signups#siteindex.com\r\n";
$headersconfirm .= "From: siteindex.com <signups#siteindex>\r\n";
$headersconfirm .= "Content-type: text/html\r\n";
$sep = sha1(date('r', time()));
$bodyconfirm = <<< EOF
(DIFFERENT EMAIL BODY)
EOF;
// Finally, send the email
mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm);
?>
You'll notice from the mail manual page, the first parameter is where the email is sent to. You haven't changed it. You have only changed the header. In order to send an email to someone else, change:
mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm);
to:
mail('signups#siteindex.com', $subjectconfirm, $bodyconfirm, $headersconfirm);
Of course, it is far more sensible to just BCC it to yourself instead of duplicating all this code.
I don't see the need to duplicate the code. Just send two emails:
$emails = 'youremail#email.com, theiremail#email.com';
mail($emails, $subjectconfirm, $bodyconfirm, $headersconfirm);
Or BCC yourself:
$headersconfirm .= 'Bcc: youremail#email.com' . "\r\n";
Take a look here.