There are many free services on the Internet. Including services for sending letters to subscribers. Some of them are very good. But since they are free, it means that advertising appears in the letters. And many people are not satisfied with the large subscription forms with the logo of the service representative.
So why not write a simple engine for your mailing list and send letters on your own?
Let's figure out what we need for this. In order for visitors to have the opportunity to subscribe to your newsletter, you need a form to enter your email address. After entering the address, you must remember it. Let's save the addresses in the maillist.txt file, one address per line. Once the address has been saved, let's display a message and display a form for subscribing to another address or deleting an existing one. That's almost all. All that remains is to add the ability to send letters. For security, let's set a password for the ability to send letters - a form is required to enter the password. You will also need forms to fill out the sender's address and subject, as well as for the text itself. And, finally, the script itself, which will send letters. And now everything is in order.
The form for entering an email address will consist only of a window for entering the address and a button for confirmation:
So, in the text input window, with the name email and a visible length of 30 characters, an email address will be entered. After clicking on the button labeled subscribe, the address will be transferred to the ras.php script for inclusion in the mailing list.
Next, let's look at the ras.php script, which will save the email address in a file, display a message about the result and forms for subscription and unsubscription. The script can be executed quite simply - save the address, display the corresponding message. But problems may arise: someone may accidentally subscribe several times, someone may make a typo and enter an invalid character in the address field. In this case, the mailing list will become polluted, and incorrect addresses will lead to errors in the script. The conclusion is clear - before saving an address, you should check it for compliance with the standards for names of electronic mailbox addresses, as well as for its presence in the mailing list. In order not to look at the code in parts, I will give comments in the code itself:
$file = "maillist.txt"; // file containing addresses error_reporting(0); // disable the display of messages about possible errors function test_mail($char) // function that checks the reality of the address ( if (preg_match("/^[_\.0-9a-z-]+@([-0-9a-z \.]+)\.((2,3)$)/", $char)) return true; return false; ) // get the address entered into the form with lowercase characters $email = trim(strtolower($email )); function copy_mail($char) // check if such an address exists in the database ( global $file; $list = file($file); for ($i = 0; $i< sizeof ($list); $i++) if ($char == trim($list[$i])) return true; return false; } echo "
Here is our code for saving and deleting addresses is ready. Now we need to take care of the means of sending mail. We won’t send via Outlook!?. As already mentioned, we will protect the ability to send with a password, which we will enter on a special form:
The input field is named pass and will be used to enter a password. After clicking on the button that says enter, the password will be passed to the out.php script:
$subject = "My site newsletter"; // mailing topic $fromemail = "my@soap"; // your address (for replies) $file = "maillist.txt"; // list of subscribers' addresses $password = "secretpassword"; // your password for the mailing list if ($_POST["pass"] == $password) // if the password you entered is correct // then we display a form with input fields: // sender's address, letter text, letter body // a button for sending // after clicking the button, we transfer the data to the send.php script ( echo "
"; print " In the database ". sizeof($maillist) ." addresses
"; for ($i = 0; $i< sizeof ($maillist); $i++) print $maillist[$i]. "
"; ) // if the password is incorrect, please enter it again else echo " ";
There is only one script left to consider - the one that will send mail:
$odr = "\n\n\n To unsubscribe, use the link\n"; $homepage = "http://site.address/ras.php"; error_reporting(0); $subject = $HTTP_POST_VARS["subject"]; $body = $HTTP_POST_VARS["body"]; $subject = stripslashes($subject); $body = stripslashes($body); $file = "maillist.txt"; $maillist = file($file); print "In the database". sizeof($maillist)." addresses
"; for ($i = 0; $i< sizeof ($maillist); $i++)
{
#echo($maillist[$i]."
"); mail($maillist[$i], $subject, $body ."$odr $homepag?delmail=$maillist[$i]", "From:<$fromemail>"); ) echo "Done!";
Everything is simple here: we receive the values entered in the previous form and send them in a cycle in turn to each of the addresses.
Copyright by Vladislav Putyak http://ru-coding.com/. Changes and additions
But then I came up with an idea on how to save money on sending mail to subscribers. How PHP Email mailing is done and what pitfalls you will encounter will be discussed in this article.
How to create a PHP Email newsletter?
PHP is a universal language, it even has a built-in mail sending function that sends emails through sendmail or another hosting utility (depending on the hosting configuration). And here the question is the number of letters. Both the mail function and the hosting utilities are quite slow. Sending one letter every 30 seconds will not get you far with a client base of 20,000. There are alternatives, for example, you can use SwiftMailer - an entire component of PHP classes that allows you to send letters with all the stuffing (attachments, signatures and all the available goodies).
But there are always pitfalls.
- Limits on the number of sendings - all hostings set limits on sending outgoing mail from a client’s account to 100-500 letters per day (this should be enough for regular correspondence, but limits the possibility of sending unwanted letters, and therefore protects the hosting from being added to spam lists) . Such limits will prevent you from sending a newsletter using the PHP mail function.
- Limits of mail providers - if you decide to use SwiftMailer or another component for sending mail, then most likely in order to use the mail servers of mail providers (Gmail, Yandex, Mail.ru) to send. SwiftMailer and others accept the credentials of an external SMTP server and send the letter directly from them. And here a flexible protection system comes into play on the part of the mail provider; it expresses suspicion of sending unwanted letters (even if they are desirable) and blocks the sending of letters.
There is an alternative, PHP Email mailing with VDS
As you can see, these restrictions greatly spoil the chances of making a newsletter in PHP. The solution may be to rent a virtual server. There are no such limits as described earlier (in general, of course, there are limits, but they are activated only when the provider receives complaints about your IP address).
So, you have a virtual server, a sendmail or smtp server is configured on it, it has its own IP address. We use sending via php mail or Swiftmailer and send letters. But be careful, sending occurs from the same IP address. That is, sooner or later this IP address will end up in at least one spam list, and the letters will begin to fall into the SPAM folder of the recipients.
What else can be done?
You definitely need to confirm that you are a real sender for a reason. To do this, you need to put DKIM and SPF records in the sender's domain settings, and attach a dkim signature to the letter. This little encrypted monster is added to outgoing emails and tells the recipient's email service that everything was sent honestly, without hacking. SwiftMailer can insert such signatures. This will also increase the mail delivery factor slightly. Read about how to configure SPF and DKIM in the following articles.
There are many free services on the Internet. Including services for sending letters to subscribers. Some of them are very good. But since they are free, it means that advertising appears in the letters. And many people are not satisfied with the large subscription forms with the logo of the service representative.
So why not write a simple engine for your mailing list and send letters on your own?
Let's figure out what we need for this. In order for visitors to have the opportunity to subscribe to your newsletter, you need a form to enter your email address. After entering the address, you must remember it. Let's save the addresses in a file maillist.txt one address per line. Once the address has been saved, let's display a message and display a form for subscribing to another address or deleting an existing one. That's almost all. All that remains is to add the ability to send letters. For security, let's set a password for the ability to send letters - a form is required to enter the password. Next, you will need forms to fill out the sender's address and subject, as well as for the text itself. And, finally, the script itself, which will send letters. And now everything is in order.
The form for entering an email address will consist only of a window for entering the address and a button for confirmation:
So, in the text input window, with the name email and a visible length of 30 characters, an email address will be entered. After clicking on the button that says subscribe, the address will be transferred to the script ras.php to be added to the mailing list.
Next, let's look at the script ras.php which will save the email address in a file, display a message about the result and forms for subscription and unsubscription. The script can be executed quite simply - save the address, display the corresponding message. But problems may arise: someone may accidentally subscribe several times, someone may make a typo and enter an invalid character in the address field, or deliberately enter nonsense. In this case, the mailing list will become polluted, and incorrect addresses will lead to errors in the script. The conclusion is clear - before saving an address, you should check it for compliance with the standards for names of electronic mailbox addresses, as well as for its presence in the mailing list. In order not to look at the code in parts, I will give comments in the code itself:
$file = " maillist.txt"; // file containing addresses error_reporting(0); // disable the display of messages about possible errors Function test_mail($char) // function that checks the reality of the address $email = trim(strtolower($email )); // get entered into Function copy_mail($char) // check if such an address exists in the database If ($flag) return true; Echo" If (is_file($file )) // then check the address using the functions described above } else print "E-mail: $email is already in the database"; } else print "Email: $email does not exist"; } else print ""; } else print "File $file not found! Please let me know me about the error."; // display a form on the screen with a proposal to subscribe and unsubscribe echo " Echo" // if the user decides to unsubscribe, delete the entered address $flag = false; $fw = fopen($file , " w"); for ($i = 0; $i< sizeof ($maillist ); $i++ ) if (trim(strtolower($delmail )) == trim(strtolower($maillist [$i ]))) ( if (!$delmail == "") { print " $flag = true; } } else fputs($fw , $maillist [$i ]); // the entered address is not in the database fclose($fw); if (!$delmail == "") if (!$flag ) print " ?> |
Here is our code for saving and deleting addresses is ready. Now we need to take care of the means of sending mail. We won’t send via Outlook, will we? As already mentioned, we will protect the ability to send with a password, which we will enter on a special form:
The input field is named pass and will be used to enter a password. After clicking on the button that says enter, the password will be passed to the script out.php:
$subject = "My site newsletter"; // mailing topic "; for ($i = 0; $i< sizeof ($maillist ); $i ++) print $maillist [$i ]. " "; } // if the password is incorrect, please enter it again else echo " "; |
There is only one script left to consider - the one that will send mail:
$odr = "\n\n\n To unsubscribe, use the link\n"; Error_reporting(0); $file = " maillist.txt"; Print "In the database". sizeof($maillist )." addresses |
Everything is simple here: we get the values entered in the previous form and send them in a cycle in turn to each of the addresses.
It’s not difficult at all! Now you have a powerful tool for running your own mailing list. There are no more rules for you. Write whatever you want in your newsletter. Complete freedom in the configuration and appearance of subscription forms.
Of course, this code is only a minimum set. For example, using the mail function, you can organize a notification for yourself about a new subscriber, and tell the subscriber about successful registration, and tell more about the newsletter.
Of course, when I spoke of complete freedom, I in no way meant forced subscription? or, more simply put, spam. If suddenly someone decides to send spam in this way, then let them take into account that the hosting administration will immediately start complaining about it. And it doesn’t matter whether the hosting is paid or not, if the hosting administration notices such actions, it will cancel the provision of its services to you without compensation for losses. And with free hosting it’s even more difficult. Firstly, you need to ask for personal permission from the administration to open this function, and secondly, as a rule, there is a limit of 1 letter per minute. So, gentlemen spammers, get off :)
Let's end on such a cheerful note.
If you have any other questions or something is not clear - welcome to our | |
|
Download a script for organizing e-mail marketing of automatic mass mailing of letters to e-mail Lasto Post Woodpecker v5.01
Characteristic:
The script does not require a MySQL database and a service for launching applications on a cron schedule, and therefore works even on free servers. The number of letters in a series can be any, there are no restrictions. The number of independently operating services is unlimited. The ability to create as many different series of e-mail newsletters as you like, and you don’t even have to create your own directory for each of them.
Directly through the Web interface, you can add a new letter to a particular mailing list in a matter of seconds, but the letter must be prepared in advance, and this message will immediately begin its journey to all subscribers of this service who have previously received a complete set of letters from this series.
It is possible to attach graphics.
- Ease of administration: the admin panel writes in great detail what it does and with which file.
- “Reasonable” behavior of the service: the script itself creates all the necessary files on the server, and also manages them, modifying and deleting them if necessary. Keeps statistics and a log of actions taken.
- Well-thought-out admin panel: you can create a new automatic mailing service in just a couple of clicks.
- Individual approach to hosting: depending on the conditions set by the hoster, it is possible to control the intensity of e-mail traffic (send many letters at once, or in small portions, but throughout the day). Some hosting companies do not allow you to send more than one letter per minute (protection against spamming), but even in this case, our script will fulfill its purpose.
- There are no requirements for knowledge of PHP by the webmaster of the resource. Although knowing PHP is useful...
Improvements included in the second version:
Connecting Crohn's in the simplest way.
- Sending a message to all subscribers of a given service, or several services at once.
- More convenient admin panel (multi-page output of all reports).
- Import and export of e-mail lists. Ability to import e-mail databases with user names (for example, taken from a smart responder).
Improvements included in the third version:
Implemented an unlimited number of attachments of any format.
- Improved email list import mechanism.
- Built-in database recovery service.
- Added a customizable service for automatic database backup (backup).
- Built-in module for obtaining statistics on subscription dynamics.
- It is now possible to exclude a specific e-mail address from all or some services. It is necessary when users with inappropriate behavior subscribe to the newsletter.
Improvements included in version 4:
The user must confirm his subscription by clicking on a special link sent to his e-mail. If such confirmation is not received, the script will subsequently remind you to confirm the subscription several more times.
- The webmaster can block some email domains for subscription. For example, the mail server from Rambler considers letters from many auto-mailers to be spam.
- The algorithm for working with serial letters has been changed.
- Temporarily disabling the script will not, after turning it on, create an avalanche of letters that should have been sent by this deadline - the letters will leave decorously and nobly at the required interval.
- The interval between each two adjacent letters of the same series can be set arbitrarily.
- Users work only with a temporary database and do not have access to the main one.
- Synchronization of databases is carried out by a script, and no one else.
- The newsletter service has been completely redesigned - this is now an independent task.
- Statistics on newsletters have been created - the webmaster now sees what stage the newsletter is in, the total number of letters, how many have been sent, how many are left.
- Added the ability to send on a schedule (launch a newsletter when a certain date is reached).
- Sender is equipped with a system for notifying the webmaster about difficulties encountered in the work. If there is a failure on the server, the webmaster will immediately know about it via e-mail.
- You can now unsubscribe from the mailing list and confirm your subscription through the e-mail interface.
- When you activate a backup via Cron, you will have daily statistics on the status of services. The script will generate a report and send it directly to your e-mail.
- The subscription dynamics section has been supplemented with graphic reports.
Improvements included in the fifth (evolving) version:
Protection has been introduced against automatic programs used by hackers to guess login and password.
- An additional stage of generating and sending a random one-time code to the admin’s e-mail has been added to the authorization process, without knowledge of which access to the admin panel is impossible.
- When navigating between pages within the admin panel, login or password hashes are no longer used.
- Gutting the browser cache (or intercepting traffic) does not threaten you in any way in terms of security.
- The database structure is no longer predetermined by default settings. You yourself change the encryption method with a special key driven directly into the script code. The key is not visible in the web interface and cannot be viewed or changed.
You can download the software posted on our website completely free of charge, we are not responsible and do not guarantee that it meets your requirements and is in working order; in most cases it will require adjustments and corrections. Correcting errors in its operation, installation on hosting, configuration is not included in our responsibilities and is carried out for a separate payment for the services of our programmer.
PHP 5.4 and higher;
- MySQL database 5.0 and higher;
- Mail();
- Iconv;
- MB String;
- Zip;
- cURL
Possibilities
PHP Newsletter has everything you need to create, send and track E-mail newsletters. This full-featured software, which was designed for email marketers, includes the following useful features:
Convenient WYSIWYG editor
The built-in WYSIWYG editor allows you to create and edit letter templates. You can format text, upload and insert images, add links, and much more.
You can create mailing lists, which will then be automatically sent out in a given order according to a schedule. All you need is to set up cron and create a mailing list.
PHP Newsletter allows you to create newsletter subscription and unsubscribe forms. You can add a form to your website; to do this, place the html code of the form on your website.
You can create attractive HTML letters or regular text emails using the built-in email template editor.
Supports most known encodings
PHP Newsletter supports over 35 different national character sets.
Adding and sending an attachment
The script includes full support for downloading and sending attachments along with your newsletter.
To prevent your emails from being classified as spam, it is recommended to add Precedence (bulk, junk or list) and list-unsubscribe headers to mailing lists.
Adding a DKIM signature to the email header
To improve the quality of classification and identification of legitimate email, PHP Newsletter allows you to add a DKIM signature (a technology for authenticating the sender of an email by adding a digital signature associated with a domain name) to the headers of sent emails.
Personalization of letters
Personalizing emails is one of the most effective ways to make a good first impression on your email recipient because, statistically, personalized emails are more likely to be opened and read. Add the %NAME% tag to the letter template and it will automatically be replaced with the subscriber's name.
Subscriber list management
Through the web interface, you can manage the list of subscribers: view, add, edit and delete subscribers.
Import/export email addresses
PHP Newsletter provides a tool to import and export email addresses. You can import data from a regular text or MS Excel file, as well as export data to a text or MS Excel file.
For each mailing, detailed statistics on the number of sent and unsent letters will be entered. You can also get information about how many users opened the emails. In addition, you can export statistics to an MS Excel file.
Web interface from administrator
To operate and manage your mailing list, you are provided with a convenient and fairly easy-to-use admin panel, accessible via the web interface. A large number of settings will allow you to quickly configure the system to suit your requirements.
Installation Wizard
Installing a PHP script can be easily launched from your web browser, for which PHP Newsletter provides you with a convenient script installation tool. You only need to enter database access and continue the installation, and the installation wizard will perform all the necessary actions.
What's new in version 5.3.x
Random replacement of the Cyrillic alphabet with the Latin alphabet (bypassing the spam filter);
- bugs fixed.
Installation
- Unpack the distribution into any directory of your website, for example, into "/phpnewsletter" You can install it in the root;
- Launch the installation wizard by typing in your browser: http://your_site/pack_with_script/install/;
- After the installation procedure, delete the "/phpnewsletter/install/" directory.
Settings
Add a newsletter subscription form to your web page
$url = "http://your_site/phpnewsletter/?t=subform";
echo $out [ 1 ] ;
For regular static web pages, paste the html code: