How to send personalized emails

I think the single most common question I've been asked over the years is “What do you use to send out your personalized emails?

It's a short little PHP script, run on the command-line, directly on your webserver. The script and simple instructions are below.

Sorry I can't play tech-support for everyone, so for anything here you don't understand yet, please ask your web-hosting company how to do this for your site. (This page is at sivers.org/emailer.)

1. Keep your list in a spreadsheet

It's important that you do it with email address in column A and name in column B like this:
spreadsheet

2. Save as tab-delimited text

Under “Save As...”, every spreadsheet program has an option to save as plain text, with the columns separated with a “tab” character. For this example, name it list.txt. Upload it to your server.

3. Here's the PHP script that does it

<?php
$from = "Willy Wonka <willy@wonka.com>";
foreach(file('list.txt') as $line)
    {
    list($email, $name) = explode("\t", $line);
    list($firstname) = explode(' ', $name);
    $subject = "Hi $firstname! The chocolate is all yours.";
    $body = "Hi $firstname - 

Those other kids are awful. You deserve it all. Come and get it.

--
Willy Wonka - willy@wonka.com - http://wonka.com
";
    mail($email, $subject, $body, $from);
    print "$email sent\n";
    }
?>

Look at it slowly, even if you don't know PHP. It's pretty self-explanatory.

  1. It goes through each line of your list.txt file
  2. Breaks each line into $email and $name, separated by tab (\t)
  3. Breaks the name into words, taking the first one as $firstname
  4. Merges $firstname into the subject and body of the mail
  5. Emails it, using the customized $email, $subject and $body

Obviously, replace the $from, $subject, and $body for your own needs. Save it as mailer.php. Then upload it to your server.

4. Log in to the command-line on your server

This is the part your web-hosting company will have to tell you how to do. Using Terminal on Mac, or PuTTY on Windows, SSH into your server's command-line.

5. Run it!

On the command-line, where the mailer.php and list.txt files are, just type:

php mailer.php
... and everyone will be sent a customized email.

comments

  1. Mary Battiata (2009-08-31) #

    I am a tech-challenged singer-songwriter and bandleader (LITTLE PINK). This was very helpful ... please keep em coming!

  2. Uke Jackson (2009-08-31) #

    Thanks, Derek!

  3. Alex Holz (2009-08-31) #

    Well-constructed, personalized emails are important in all businesses. Microsoft Word/Outlook/Excel can handle mail merge with efficiency and a good alternative for those who don't want to deal with PHP.
    Using this directly from your server (instead of your home PC) also helps get by any ISP limits for sending thousands of emails. -- Derek

  4. Mark Gresham (2009-08-31) #

    I assume this is exactly what HostBaby's existing e-mailing-list widget already does in terms of PHP, maybe with some extra bells and whistles? Despite how long I've been there as a client, I've never bothered to use that widget (maybe it's time?)
    Yeah HostBaby's “listbaby” feature is really just this, enhanced, with a web interface. -- Derek

  5. David Stevenson (2009-08-31) #

    Pretty awesome nugget of you to share with the masses! If you're comfortable, you should use a database (like mysql) so that people can signup online and you don't have to update the list manually.

    I used to use phpList, too, which is pretty straight forward.

    You rock and roll Derek - thanks for your blogs/ideas/insights/genius!

    -David

  6. Raul Del Corte (2009-08-31) #

    Thank's, Derek. Very interesting!

    Regards,

  7. Igor Olejar (2009-08-31) #

    I agree with David Stevenson. phpList is simple, easy and reliable.

    It's also very simple to install.

  8. Marie Angell (2009-08-31) #

    Are personalized mass emails really important? I don't really care for them; they seem phony to me.
    I just think it's considerate. Also comes in handy for getting advanced with things like including an “unsubscribe” link at the bottom that already knows who they are. -- Derek

  9. Ike Barnes (2009-08-31) #Ike Barnes

    I use phplist that my host provides for free it has the same functionality and is very simple to set up. It's basically the same process but instead the app handles it for you. Thanks Derek!
    Yep. phplist is great. But since people ask what I use, this is what I use. -- Derek

  10. Peter Lucibelli (2009-08-31) #

    I will save this valuable information but I am tech challenged. This will come in handy as I am sick of the 200 plus people I email to and all address are to be seen.

    Thanks! Do you ever rest?????
    You don't have to understand it yet. Just show it to your web-hosting company or a tech friend and tell them you want to do this. -- Derek

  11. Brian Caldwell (2009-08-31) #

    I was wondering, where do you get your energy - how much coffee do you drink?

    Seriously though, thanks again for all the great stuff you share.

  12. Ronnie Marler (2009-08-31) #Ronnie Marler

    That's great for those wanting to dip their toe in to the php pool. If you want to jump in and swim check out this open source list management system.I use it and it rocks
    phplist(dot)com
    Click on my name to see it in action

  13. Ken K (2009-08-31) #

    Doesn't this script also send the emails one at a time? I suspect this eliminates the problem of needing to send to lists of less than 100 (or so) recipients that many email providers instate for spam protection.

    Curious why you don't keep the first and last names in separate fields in the source spreadsheet - wouldn't this handle two-name first names better (Mary Ann, John Paul, etc.)?

    Thanks for sharing this... good stuff, as always Derek!

    peace,
    ken k
    Yes, it sends the emails one at a time (since each email is unique). And it shouldn't bump up against any email provider, since your server itself is doing the emailing, not any ISP. As for names: asking thousands of people to accurately keep their first and last names separated in my system puts too much work on them, when a single line of a PHP script can do it instead. -- Derek

  14. David A. Boyington (2009-08-31) #

    Thanks Derek! I appreciate your time spent to share this very useful information. Peace.
    David A. Boyington
    Radio Producer

  15. Matthew Cameron (2009-08-31) #

    I did this myself for a while as well - tried Constant Contact and it is amazing. Love love love being able to see which emails work and which do not (stats and reports) have found that text emails sometimes (particularly for press releases) are more effective than HTML.

    Contact Contact is pretty cheap too - but I do keep and maintain my own list (just upload it to CC by the zip's where I am doing a concert ... why tell Seattle when the gig is in Texas and so on?)

  16. Wes Carroll (2009-08-31) #

    It's incredible, Derek, that more people don't understand the enormous power of explaining in easy-to-understand terms the knowledge that they have long since taken for granted.

    Kudos and thanks!

  17. Tempy and Sam (2009-08-31) #

    once again derek, you are sooooooooooo da bomb cowboy!!!=)

    love, light & gratitude,

    tt & the planet cowgirl herd=)

  18. Dan Shure (2009-08-31) #

    Derek

    Great post. A great practical shift from the more philosophical posts. I know you are not here to be everyone's tech but is there a book or two you might personally recommend for those of us just beginning to learn PHP (already with knowledge of HTML and CSS)? Or other advise for someone starting down that path? Any thoughts other readers might have would be helpful too. Thanks!
    For beginning PHP, the Head First PHP + SQL book is best. It's really different from any other computer book. They're really into the science of what helps people learn. I love their whole “Head First” series. -- Derek

  19. Peter Ncanywa (2009-08-31) #Peter Ncanywa

    Hostbaby makes this a tad easier ;-)

  20. Trevor Reid (2009-08-31) #

    Yes, I often Wonder how you do it.
    But. I always appreciate every time
    you send an email, it makes me feel
    like you take the time to check up on us musicians and give us links and answer any of our questions that we asks you. Really, how do you do it?

  21. Mark O'Meara (2009-08-31) #

    If your hosting company/website package lets you use a database, then the Listmessenger software will really allow you to customize emails with templates, graphics etc and allows people to automatically sign up with double opt-in. Its not expensive, and very reliable. Visit listmessenger.com for more details.

  22. Luko Adjaffi (2009-08-31) #

    thank you you are the best one of the best tll tham all how bless you are ...in the tech world ...we are in a big community of intelligencers...luko adjaffi

  23. Mikal (2009-08-31) #

    RE: PHPLIST

    It's great, unless you are running it with a webhost who gives no support on it! I've had issues just appear with it out of nowhere, and my webhost is no help at all. And it's rare that anyone on their help forum actually knows how to help.

  24. Shaquita Rolland (2009-08-31) #

    I think the php list is useful and a time saver.

  25. Mikal (2009-08-31) #

    Peter Lucibelli - Even if you did send email to 200 people directly from your email provider, you don't have to allow all of the addresses to be seen. Put them in the BCC or Blind Copy field. This prevents them from being seen by everyone who receives the email.

    However, I would not recommend emailing such a large number of people directly from your email account. This will be detected by many services as spam, and you will possibly get your email automatically blocked by many sources, therefore rendering your email list useless. I would definitely use some sort of list system, whether it is Derek's, PHPLIST, or any of the other free and/or pay systems available.

  26. Steve Ferguson (2009-08-31) #

    Thanks for all of the articles and info, Derek. I have wondered also about this aspect. Be well, Steve.

  27. dwight l. quinn (2009-08-31) #

    Thanks Derek, I will start using this. I like the idea of having my own Email program, We are using more and more email marketing today, ever and it's getting larger. With this I can see a huge savings in time,efforts and money..

  28. Corey Koehler (2009-08-31) #

    I am unclear as to where this falls in the "funnel". Does this replace an autoresponder program (say Aweber)? Or is it in addition to it?

    I guess I do not see how this is any more personal than that or my just using a separate email address (gmail, yahoo, etc) to handle this type of correspondence.

    Did I miss something?
    This is what I use to send outgoing mass-emails to people I know. So that every email is almost the same, but customized for the person a bit. (In this example “Hi Agustus...” - “Hi Veruca...”) -- Derek

  29. Tamara Nile (2009-08-31) #

    i adore these updates. i look forward to them every day. thanks derek!

  30. Efrat Darky (2009-08-31) #

    Thanks so much.

    looking for your amaizing e- mails


    Luv

    Efrat

  31. Mark Johnson (2009-08-31) #

    Hi Derek,

    I'm computer stupid when it comes to things like this. My main problem with not getting more fans on ReverbNation is due to I don't know how to mass e-mail to others who are also on ReverbNation.

    Can I find the book you mentioned to help me with this at any computer store?

    Peace

    ~Mark~

  32. David Barr (2009-08-31) #

    Derek I look Forward To these jewels of info. Thanks.

  33. Charles Nwabueze (2009-08-31) #

    Hello Derek, it's great sharing some email techs/tip knowledge. I think we have been using something similar with Hostbaby and it works well.

    However, we realized that when we send more than 3000 emails at a time, it takes a lot of it to the junk of recipients.

    As some told us about this issue, we came up with an idea to reducing the number we send at a time. What we do now is to have 200-300 per send. And it works better with better feed backs.

    Yet, it would have been much preferable, as our other auto responders, to send more than 5000 emails without let or hindrance.

    Pls, we could be getting it wrong too.

    Thanks for the sharing.

  34. Rhonda Ann Clarke (2009-08-31) #

    Thank you sooooooooooooo much Derek! You are helping sooooooooooooooooooo much!!! I have forwarded this posting to my genius web guy in Thailand who is very much appreciating your genius mind!

  35. Leanne (2009-08-31) #

    Frankly, your example names and email addresses was the best part!

  36. ade ishs (2009-08-31) #

    Derek, seeing that you don't check the return value of mail(), I guess you don't really care that if there are messages not accepted for delivery? Things probably rarely go wrong with you, but I'd just add a bit to the last two lines:

    $status = mail($email, $subject, $body, $from);
    print "$email ";
    if (!$status)
    {
    print "not ";
    }
    print "sent\n";

  37. Dan-O | DanoSongs.com (2009-08-31) #Dan-O | DanoSongs.com

    For the tech challenged you can also use the feedburner email subscription feature that will send your blog posts via email directly.

  38. Dixon (2009-08-31) #

    Far too techie for me. I'm hard pressed to find the 'puter "on" button.

    'Can't find matching socks in the morning either.

  39. Alex (2009-08-31) #

    This is all very well but there are much better solutions with way more options and much more user friendly, some for free, some very inexpensive. I use Mailmachine Pro for instance which is only $35.

  40. William (2009-08-31) #

    Great break down of easy to do coding. But it would be good to have a test file with just your personal email to see how it looks before doing mass email. One tiny typo and the messages could be garbled... Just like music, practice before the performance. smile

  41. Juliana McCorison (2009-08-31) #

    You know... you just can't please everyone...

    Thanks for the info. I will admit that it breaks my heart that you've not writing these emails just for me but... It's nice to get personalized information regardless and I appreciate the info on how we can do it if we want to!

    Thanks Derek -- I don't know about da-bomb but I do know you're great!

  42. Gary Wood (2009-08-31) #

    Whoosh, right over my head, dude. I though PHP was some kind of animal tranquilizer.

  43. George Finizio (2009-08-31) #

    Thanks for the tips Derek, sounds like a very useful tool!

  44. Mick Flores (2009-08-31) #

    Derek thanks for the tutorial.

  45. Linda Sadowy (2009-08-31) #Linda Sadowy

    Thx Derek You rock!!!!

  46. Rick (2009-08-31) #Rick

    I've been looking for a solution to this simple problem for a while!

    Thanks to Alex for the tip about MailMachinePro, and thanks to Derek for getting the conversation started!

  47. Georgie C (2009-08-31) #

    Derek you beauty!

    Thanks
    Georgie C

  48. Frank Tuma (2009-08-31) #

    Hmmm,I'm going to have to get me into this.I don't do enough for my customers.
    Thanks
    Island Frank

  49. Julie Lendon Stone (2009-08-31) #

    Thank you,Derek. This is great. I'm wondering if it will work on Hostbaby, since I'm using the templete. I'll find out. Thanks again.

  50. Kyle Knapp (2009-08-31) #

    Thanks Derek! I might try this. But I have 2 questions:

    1.My web host limits me to 500 messages an hour, but my list is around 1500. How hard would it be to insert a "pause" in this script?

    2.Can you embed HTML tags in the $body section?

    Blessings,
    ~kyle
    1. Because the email-sending would be done directly by your server, this should bypass all limits. 2. No this won't work for HTML. That's surprisingly complicated. For HTML-emails use a different service. -- Derek

  51. Dr.X/Solomon (2009-08-31) #

    Mannn Derek,
    Thanks that's some real internal office internet
    S......T Bra., !!!

  52. Pete Berwick (2009-08-31) #

    My brain hurts

  53. Richy Kicklighter (2009-08-31) #Richy Kicklighter

    Derek, is there a program downloadable or website where email programs are set up for this already to go?free?
    Lots. See the the other comments here. Also FanBridge.com. -- Derek

  54. Andy Duinker (2009-08-31) #

    Oh my!
    I am having a hard enough job juggling my music biz. I really need to sing and perform and record way more and do this stuff way less. I don't really get it and will try to deffer to someone who can handle and likes this tech stuff. Please Lord, send me someone who can help me and not get paid----yet.
    You're a good fellow Derek. Can you come up the the ECMA's again?

  55. Felix (2009-09-01) #

    Hi Derek
    Delightful as always!
    What are you programming? sounds intriguing.
    I know it was a different post, but you were spot on about one website distribution for bands.
    positive vibes from london
    Felix x

  56. Michael (2009-09-01) #

    Nice one Derek - thanks for sharing the techy stuff.... That's really helpful smile

  57. Lee Cutelle (2009-09-01) #

    Thanks....Any technical advice is always handy.

  58. Pete Fegredo (2009-09-01) #

    Thanks a ton Derek.This is very useful.I always wondered about this.

  59. Ed Lagace (2009-09-01) #

    Thank you Derek.

  60. Cyril Darensbourg (2009-09-01) #

    thank you for the help

  61. Gen Berthault (2009-09-01) #

    Ohhhh. Now I get it. But had to read all the comments before it sank in. Fantastic.

  62. Mykel (2009-09-01) #

    PHP list rocks. I use it often.

    great share Derek!
    Mykel

  63. Valentin Gavan (2009-09-01) #

    Interesting stuff, thanks for sharing.

  64. Dennis Hitchcox (2009-09-01) #

    Since there's ReverbNation.com, my e-mails are a cinch, and they look very pro. In your earlier blog about using your web site as the definitive source for all of your info?.... well with their handy widgets and connectivity to the social networks, you can manage all that stuff from one place. Reverb Nation has made my life so much easier. Just in case you haven't heard of RN, it could really streamline your efforts: e-mails, shows, widgets, videos, marketing, etc.

  65. Spencer Crandall (2009-09-01) #

    Thanks for sharing your code. For the less technically inclined, I'm with Hitchcox. They have a free (up to 500 names) e-mail system that manages contacts, plus generates a signup widget you can place on your website. You can export this list to Excel at anytime for backup (in case any e-mail company fails, you need to make sure you own your list). After sending messages you can track opens and click-through rates too.

  66. Ricky (2009-09-01) #

    Hey Derek,

    Great content as usual. I currently use another php software called parabots which I bought a while back and it works great. It was a little tedious to set up but once running it has a nice web interface for non-techies like me. I paid I think $49 for a copy but I just checked their website (www.parabots.com) and now it's free. Bummer for me but good news for everyone here smile

  67. Bethany Dalton-Kash (2009-09-01) #

    Thanks Derek!

  68. Aum Soham (2009-09-01) #

    Thanks. It was great.

  69. Omoleye Gomez (2009-09-01) #

    Derek, Thanks for the information. it certainly does not make much sense to me. i got to hear about this programming language from you. i need to know more about it. could you recommend the books you read from scratch on this PHP. am going to wikipedia from here. i guess, i have been living under a rock in Africa(LOL)

  70. Mike Maxwell (2009-09-01) #

    Thank you Derek. Although I can see the plus side of this as convinient, I send out my emails seperatly with a personal touch for each. Thank you for the great info!!
    You Rock,
    Mike

  71. Andrea Hector (2009-09-02) #

    heh...don't know where all you learned how to use php...but i'll tell ya...ya had me lost at step 3. lol! I'll stick to composing.

  72. sandy famiglietti (2009-09-02) #

    To better employ time we must spend the time to know it; then without fear we call "today" our own.

  73. Kristen T. Clark (2009-09-02) #

    OMG!! I never needed anything like this til just this week! Your timing is impeccable Derek! Where can I print this out? I'm being limited by Outlook Express on how many emails a day I can send. So I need this quick!! LOL!

  74. Dave (2009-09-03) #

    Thanks a bunch.

  75. Stefan Daniel Bell (2009-09-03) #Stefan Daniel Bell

    derek..

    lol. so you are saying You are the mail merge program?!!! (well programmer).

    you are amazing. my brain is now bent.

    i would say it is over my head. and. knowing the importance, i will absorb slowly and learn...

    thank you
    stefan
    Just saying it really only takes a few lines of PHP to merge a name into a unique email. smile -- Derek

  76. Ryan Crouse (2009-09-04) #

    Thanks Man, you always give out GREAT Tips!! smile

  77. Janet Beatrice (2009-09-07) #

    You mean we don't have to subscribe to Aweber or Constant Contact? That's amazing.

    Besides being a musician, I'm a copywriter, and most of us are tied to autoresponder software. This will save us some money!

    Thank you.

    Janet Beatrice
    HeartBeat Children's Music
    Copy with Heart
    Website Building 4 Newbies

  78. Sam Soul (2009-09-09) #

    Very useful. Why are you telling us your secrets though???!

    You have always been there to help us indies...!

  79. Edwin (2009-09-11) #

    Thank you Derek.......

  80. Joe Matzzie (2009-09-13) #

    Very Cool. I find this interesting because I know you used to use Filemaker Databases for contacts. You posted something years ago, maybe on the musicthoughts list, about advice on using keywords in a DB. I started using Filemaker for all my contacts based on that advice and still love the DB but recently a client of mine had me start using spreadsheets so we could share them between out computers.

    I'd love to hear your thoughts on the pros and cons of spreads vs databases, and whether you still keep your peeps in a database or you just went all spreadsheets.

    BTW you misspelled Mike Teevee http://www.imdb.com/title/tt0067992
    Boy he's gonna be pissed. Ha ha
    Databases, definitely! I just assumed that most people aren't ready for a real database yet, so spreadsheets are an easy place to start. Easy to import a spreadsheet into database. -- Derek

  81. Jeff Miller (2009-09-14) #

    I am surprised that that many people care how to do this. I think most people who get these emails know that no one actually took the time to put their name in the greeting on the email.

    To me, "personalized emails" aren't really personalized, if they're done in this fashion. I don't really see the worth of it. If people sign up for a Newsletter, for example, then they know that they will be receiving it in addition to hundreds or thousands of other people.

    Now if someone could tell me how to not get AOL addresses to bounce back to me on all my Newsletters, that would be helpful.

  82. Paula Benson (2009-09-24) #

    Thank you Derek.

  83. Nick Yeoman (2009-10-01) #Nick Yeoman

    Wow, I'm not sure how you got so many readers on this article as any php developer can do this.

    But people love it, so great job!

    Wish my blog nickyeoman.com was this popular.

  84. Brian Theoret (2010-01-26) #

    This is JUST what I was looking for. Couldn't be easier!

Your thoughts? Please leave a reply:



  (kept private! never shared.)





Derek Sivers