<html lang="en" dir="ltr">
<title>How to send personalized emails | Derek Sivers</title>
<meta name="description" content="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?”">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/style.css">
<link rel="alternate" type="application/atom+xml" title="Derek Sivers" href="/en.atom">
<link rel="alternate" type="application/rss+xml" title="Derek Sivers podcast" href="/podcast.rss">
<link rel="prev" href="https://sive.rs/sprezzatura">
<link rel="next" href="https://sive.rs/drama">
<h1><a href="/" title="Derek Sivers">Derek Sivers</a></h1>
<div class="blogparent"><a href="/blog">Articles</a>:</div>
<h1>How to send personalized emails</h1>
I think the single most common question I’ve been asked over the years is “<strong>What do you use to send out your personalized emails?</strong>”
It’s <strong>a short little PHP script, run on the command-line, directly on your webserver</strong>. 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 <strong><a href="/emailer">sive.rs/emailer</a></strong>.)
<h3>1. Keep your list in a spreadsheet</h3>
It’s important that you do it with <strong>email address in column A</strong> and <strong>name in column B</strong> like this:
<br /><img alt="" src="/images/wonkakids.png">
<h3>2. Save as tab-delimited text</h3>
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, <strong>name it list.txt</strong>. Upload it to your server.
<h3>3. Here’s the PHP script that does it</h3>
$from = "Willy Wonka <email@example.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 — firstname.lastname@example.org — http://wonka.com
mail($email, $subject, $body, $from);
print "$email sent\n";
<p><strong>Look at it slowly</strong>, even if you don’t know PHP. It’s pretty self-explanatory.</p>
<li>It goes through each line of your list.txt file</li>
<li>Breaks each line into $email and $name, separated by tab (\t)</li>
<li>Breaks the name into words, taking the first one as $firstname</li>
<li>Merges $firstname into the subject and body of the mail</li>
<li>Emails it, using the customized $email, $subject and $body</li>
<p>Obviously, <strong>replace the $from, $subject, and $body</strong> for your own needs. Save it as <strong>mailer.php</strong>. Then upload it to your server.</p>
<h3>4. Log in to the command-line on your server</h3>
This is the part your web-hosting company will have to tell you how to do. Using <a href="http://www.osxterminal.com/">Terminal</a> on Mac, or <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> on Windows, SSH into your server’s command-line.
<h3>5. Run it!</h3>
On the command-line, where the <strong>mailer.php</strong> and <strong>list.txt</strong> files are, just type…
…and everyone will be sent a customized email.
© 2009 <a href="https://sive.rs/">Derek Sivers</a>.
« <a href="/sprezzatura" accesskey="p" rel="prev">previous</a>
<a href="/drama" accesskey="n" rel="next">next</a> »
Copy & share:
<span class="url"><a href="https://sive.rs/emailer">sive.rs/emailer</a></span>