~sivers/sive.rs

ref: b2f50afe9f3a46f2848387525ab5fefcaad1de58 sive.rs/site/emailer -rw-r--r-- 4.2 KiB
b2f50afe — Derek Sivers ArtistData is gone 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<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">
</head>
<body id="article">
<section id="masthead">
<h1><a href="/" title="Derek Sivers">Derek Sivers</a></h1>
</section>
<div id="content">

<article>
<header>
<div class="blogparent"><a href="/blog">Articles</a>:</div>
<h1>How to send personalized emails</h1>
<small>2009-08-31</small>
</header>

<p>
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>”
</p><p>
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.
</p><p>
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>.)
</p>
<h3>1. Keep your list in a spreadsheet</h3>
<p>
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">
</p>
<h3>2. Save as tab-delimited text</h3>
<p>
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.
</p>
<h3>3. Here’s the PHP script that does it</h3>
<pre>
&lt;?php
$from = &quot;Willy Wonka &lt;willy@wonka.com&gt;&quot;;
foreach(file(’list.txt’) as $line)
    {
    list($email, $name) = explode(&quot;\t&quot;, $line);
    list($firstname) = explode(’ ’, $name);
    $subject = &quot;Hi $firstname! The chocolate is all yours.&quot;;
    $body = &quot;Hi $firstname — 
Those other kids are awful. You deserve it all. Come and get it.
--
Willy Wonka — willy@wonka.com — http://wonka.com
&quot;;
    mail($email, $subject, $body, $from);
    print &quot;$email sent\n&quot;;
    }
?&gt;
</pre>
<p><strong>Look at it slowly</strong>, even if you don’t know PHP. It’s pretty self-explanatory.</p>
<ol>
<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>
</ol>
<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>
<p>
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.
</p>
<h3>5. Run it!</h3>
<p>
On the command-line, where the <strong>mailer.php</strong> and <strong>list.txt</strong> files are, just type…
</p>
<pre>php mailer.php</pre>
<p>
…and everyone will be sent a customized email.
</p>

<footer>
© 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> »
)
<h1>
  Copy &amp; share:
  <span class="url"><a href="https://sive.rs/emailer">sive.rs/emailer</a></span>
</h1>
</footer>
</article>
<div id="comments"></div>
<script type="text/javascript" src="/js/comments.js"></script>

</div>
</body>
</html>