Very simple subscribe form for under construction page - php

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.

Related

Email sending issue from PHP website [duplicate]

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

Get all rows into a variable then mailto for each PHP

So, I found this thread (Get all data from mysql row in a variable) but I am too much of a beginner to make it apply easily to my situation. Thank you for helping me out... sorry for the total newb questions.
I have a PHP form that lets the user select one of my tables in a database where email addresses are stored to send an email to each of them. Right now, I have this code:
$recipientid = $_POST['recipientid'];
$body = $_POST['body'];
$subject = $_POST['subject'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: SENDER NAME <senderemail#gmail.com>' . "\r\n";
date_default_timezone_set('America/Los_Angeles');
$time = date('m/d/Y h:i:s a', time());
$sendbody = $body . "<br><br>This is a bulk email announcement sent by
the institution.<br><br>It was sent at " . $time . ". If you have any
questions about this message or wish to unsubscribe, please contact
the institution.";
if($recipientid == 'allstudents'){
// SEE NOTE #2//
$recipientlist = //email addresses
}
$process=explode(",",$recipientlist);
reset($process);
foreach ($process as $to) {
$sent=mail($to,$subject,$sendbody,$headers);
}
if ($sent) { //(success echo goes here... it is quite long so i removed it.)
} else {
echo "Email could not be sent, PLEASE CONTACT US.";
}
What is the easiest way to capture all of the email addresses in the column of the specified table and then loop a mailto for each? I was originally trying to get them all into one string and then explode them as you can see, but that might not be the best solution. Am I on the right track here?
(NOTE #2 FROM IF)
HERE IS WHERE I NEED SOMETHING... I was sort of thinking about trying to use the following. I need it to grab all the emails from the column emailaddresses in the table students. I am using an if statement because there are four other things that $recipientid could equal, and each different one grabs email addresses from a different table.
array pg_fetch_all_columns ( resource $result [, int $column = 3 ] ) But then, I don't know how to get this array to work with my mail. I originally tried to use just a SELECT * from emailaddresses and then use each row somehow but I don't know how to implement that.
YES, I know I am using mysql not mysqli and I know that mailto is probably not the best solution, but it is what I have to work with right now (unless you can suggest an alternative route for the mail loop).
Thank you again! I really want to learn what I am doing, so an explanation would be appreciated:)
(and ps I am using the mail function with the explode because of this article http://tutorial.world.edu/web-development/php-script/how-to-send-out-mass-emails-php-script/)
I might be a little confused about the question. It sounds like you have a database with email address and you want to send an email for each email address. I think you can just do the query SELECT emailaddress from table and cycle through the results and use your mail function each time.
$query = *your select query*
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$sent=mail($row['emailadress'],$subject,$sendbody,$headers);
if ($sent) { //(success echo goes here... it is quite long so i removed it.)
} else {
echo "Email could not be sent, PLEASE CONTACT US.";
}
If you want your user to select the table the email addresses are coming from you can use a form and a variable in the query.
You can use the below piece of code to send the mail.
Consider you have an email field in your table 'students'
then
$sel = mysql_query("select email from students");
while($info = mysql_fetch_assoc($sel))
{
$to = $info['email'];
$sent=mail($to,$subject,$sendbody,$headers);
//---Remaining code goes on
}
try it.

Password reset using PHP and urlencode issues

Just looking for advice on how to apply the urlencode into this bit of code. It is actually working, the issue when the email is received, the urlencode doesn't seem to work.
function reset_password($email) {
$query = "DELETE from reset_password where email = $email";
$deletepass = mysql_query($query);
$code = substr(base64_encode(crypt('', '')), 0, 32);
$query2 = "INSERT into reset_password values ($email, '$code', " . time() . ")";
$insertval = mysql_query($query2);
$f = "SELECT userEmail from gn_users where email = $email";
$from = "***"; // sender
$f['userEmail']; // recepient
$message =
"From: *** <***>\r\n" . // email headers
"To: {$f['userEmail']} <{$f['userEmail']}>\r\n" .
'Subject: Reset Password' . "\r\n" .
"\r\n" .
"Hello\r\n" . // email imap_body(imap_stream, msg_number)
"\r\n" .
"A request has been made to reset your example.com web site password.\r\n" .
"\r\n" .
"To complete the request, click on the following link within 48 hours of the transmision of this email and follow the on screen instructions.\r\n" .
"\r\n" .
"index.php?page=reset-password&email=" . urlencode($email) . "&code=" . urlencode($code) . "\r\n" .
"\r\n" .
"Kind regards,\r\n" .
"\r\n" .
"The example.com Web Site";
$to = "$email";
$subject = "Test mail";
$message = "$message";
$from = "***";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";}
I'll try to help you out with some tips to write one yourself, without having to rely on that awful code.
You need to break the task down in multiple, bite sized, easy to do tasks.
Here we go:
The user needs a page where to request a password reset. It's a form with an email field (and/or username).
We have the user email, and if it exists, we need to generate a reset password link that can't be guessed, so that not everyone can reset someones password.
So you need to generate a unique hash for this request, an option would be uniqid(), but there are many options here. So you generate a link that looks like: http://test.com/reset.php?uid=443&hash=33rr3344rree22. It can't really be guessed because you need to know both the user id and the has. But to make sure, we will make it expire in an hour or day.
Next, we ensure that this link will work. We have to create a table for password reset requests that contains the following columns: id, email, hash, date_added, and insert it (the date can be TIMESTAMP with a default of CURRENT_TIMESTAMP).
Now it's time to send the email. You can add any text you want, as long as you mention the url you generated a bit earlier.
Now the user clicks the link. You get the user id and hash, and check if such an entry exists. If it does, and the request is not older than 1 day, we generate a new password, update the users table, and send him a confirmation mail.
This is optional, but recommended. Create a cron job that clears the password reset request table for entries older than 1 day.
Each of these steps are fairly easy to do, or you can find a lot of information about them around the web. If you take your time to understand each step, sanitize everything properly, and do things by the book, you will learn a lot.

Limit contact form emails per second/minute

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

Sending Email to Multiple Recipients from MySql Recordset

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.

Categories