Email Newsletter Subscriptions Using PHP and Dreamweaver
I had an interesting email from a reader recently who said that he designs simple sites for non profit organizations and whether or not the Contact Forms Using PHP or ASP would be the way to go for a Email Newsletter opt in?
In my opinion, I wouldn’t use those forms for that purpose but in this article I will show you how you can achieve this through the use of Dreamweaver CS3 and PHP.
NOTE:This is a 2 Part Series so make sure you Subscribe so you don’t miss the next article.
First thing we need to do is create a database to insert the records into. Now that I have XAMPP Installed on my Windows Vista box I can do all this locally. For this example I have created a database called EmailSubscriptions with one table called ESubscriptions.
This table has 4 fields, ID, Name, Email, Subscription. The ID column is the Primary Key and it auto incremented. The Name field is there to hold the name of the user, The Email field is a text field and will hold the users email address and the Subscription field will handle whether the user is subscribed or not, it is a Boolean field and 1 indicates subscribed, 0 means unsubscribed.
Next Step is to open up Dreamweaver and connect to the newly created Database. Here we go.
1. The Applications Panel
In the Applications Panel on the right hand side of Dreamweaver and select the Databases Tab. Cick the + icon and select MySQL Connection. Give the connection a name, pop in the name of the database server (in my case and most cases this will be localhost), provide a username and password of a user that has access to that database, and then select the database from the list by clicking the SELECT Button. Click TEST and see if you have connection. If not then double check you have entered the correct values into the fields.

Let’s no have a go at building the subscription page……
2. Insert a Form and Add Some Fields, Then Create an Insert Record Server Behavior.
Insert a Form onto a New Page and save the page Subscribe.php. Inside the form place a label for Name and a Text Box with an ID if txtName. Also place a label for Email Address and a Text Box with an ID of txtEmail.
We now need to insert a Hidden Field so that the Subscription Field in the database is populated with a value of 1. On the Insert Menu at the Top select Hidden Field. This then inserts a hidden field onto the page.

If you double click the Hidden Field icon on the page the Property Inspector will open up. Give the field a name of Subscription and a value of 1.

Let’s now Create an Insert Record Server Behavior. First we need to create a Binding. So from the Application Tool Pane on the right select the Binding Tab and create a Record Set, give it a name and then select the EmailSubscription Connection you created earlier and there should only be one table in there. Click the TEST button to test the connection.
Then from the Server Behaviour Tab click the + Icon and then select the Insert Record Behaviour. Select the correct Form, Connection, and Table from the drop down menus (there should only be one item in each anyway).
Populate the Database Column With The Correct Data
In the Columns section we need to make sure that the database fields are being populated with the correct data. To do this select the line that starts with Email and then from the Value: drop down menu select FROM.txtEmail. Do the same for Name. The ID is auto generated and the Subscription field is hidden and we have already given that a value. In the After inserting goto text box type in confirm.php and then create a new php page with that name. That is the page the visitor will get after they click the submit button.

Create The Conformation Page
Let’s open up the confirmation page now and add some text to it. Now I want to make this page a bit more personal so I am going to add the users name and email address that they supplied as well to the message. To do that we need to add the fields through a RecordSet.
From the Application Tool Pane > Bindings Tab Create a New Record Set and give it a name, choose your connection, and select the table. Next SORT the ID Column by Descending order. Click Advanced button to open up the advanced sql options.
In the SQL text area you will see the line that reads: ORDER BY ID DESC
add LIMIT 1 to the end of it. What that will do is return just one result and it will be the last one entered. Click OK.
Now place your cursor in the spot that you would like the users name to appear and from the Bindings Tab on the right expand the record set that you created and click on Name and then click INSERT.
Ok, this is where the good stuff starts!…….
Using PHP’s mail() method we can send the email to the end user. The method looks like this:
mail(address, subject, message[, header[,parameters]])
The first 3 parameters are required. Next I want to create a few variables to make things a lot easier.
$id = $row_Subscriber['ID'];
$to = $row_Subscriber[Email'];
$subject = “Subscription confirmation”;
The first 2 pull data from the newly inserted record and the 3rd will be the subject line of the email. Where it says Subscriber, this is the name of your Record Set.
Below is the entire code block that I used, and placed in between the
tags.
<?php
$id = $row_Subscriber['ID'];
$to = $row_Subscriber['Email'];
$subject = "Subscription confirmation";
$body = "<html><body>" .
"<h2>Thank you for subscribing to our newsletter!</h2>" .
"<p>To unsubscribe, click here.</p>" . "</body></html>";
$headers = "From: Subscription Manager <someone@mycompany.com>\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=UTF-8";
if (!mail($to, $subject, $body, $headers)) {
header( 'Location: http://[YOUR SERVER & PATH HERE]/error_subscribe.php' ) ;
}
?>
The line that needs adjusting in the one that starts with header. This will be the page that the user gets taken to if there is an error sending the email. So create a page for this and put the path in there.
There we have it. Now I will let you know that I tested this using Blue Host so if you are using a different host I would love you to share with the readers which host you used and what the outcome was.
In the Follow Up Article I will go through how you can let the user unsubscribe from the list so make sure you SUBSCRIBE to the RSS Feed to get that one.
You can follow any responses to this entry through the RSS feed. You can leave a response, or trackback from your own site.


May 9th, 2008 at 5:46 pm
Hi Daniel,
You’re a cornucopia of web development info! I don’t see your About page but I’m guessing you’re a developer - great job with your tutorials, you’d make a good teacher.
May 10th, 2008 at 10:23 pm
thank you for your incite on this program you have been lots of help to me.
August 18th, 2008 at 8:15 am
the mail part does not work
August 27th, 2008 at 9:29 pm
thanx a lot i got thru the tutorials but wasnt really clear and practical.
it gooes thus
- i have a form for which i have created,purposely to be sent to an email in box.(macromedia dreamweaver)
-i need to secure the informations in the form,and give a return msg of form being successfully sent else error page.
-how do i go about this using php,where do i embed the php code,how does the information in the various fields get catured and sent into the specified inbox.
pls tutor me on the practical step step procedures to take.
thank you
September 2nd, 2008 at 2:02 am
[...] addthis_pub = ‘ultra’; addthis_brand = ‘Ultrashock.com’; addthis_options = ‘favorites, google, delicious, digg, facebook, fark, furl, live, myweb, myspace, newsvine, reddit, slashdot, stumbleupon, technorati, twitter, more ‘; Dreamweaver, PHP, and MySQL 1 Minute Ago I have been doing an online tutorial for email newsletter subscriptions using Dreamweaver, PHP, and MySQL. My only problem is that when it sends a confirmation email it sends it twice to the user. I can’t seem to figure out what I am doing wrong. I have provided the link below if anyone wants to walk through and do the tutorial. I have done the tutorial three times and I still get two confirmation emails. http://dreamweaverspot.com/email-new…aver/#more-156 [...]
September 4th, 2008 at 5:08 am
Hey, great tutorial.
Before I start implementing this on my project I´d like to ask if I only want to collect e-mail address and not names or anything else. Could I just strip out these lines of code and use the rest?
Also How will a site owner access the records? Perhaps that is explained already but if the site owner is a non tecchie is there some accessible way for her to see the records of the database?
Appreciate your site
/Jake
September 8th, 2008 at 4:27 am
I get two confirmation emails instead of one!
November 14th, 2008 at 9:30 am
hey,
I’m not too familiar with creating databases so getting a little stuck creating the 4 fields for the entry (ID, Name, Email, Subscription).
I have my phpadmin open, my database is created and I’ve gotten to the stage to edit my 4 table fields.
I’m not sure what you put for, Lengt/values, Collation, Attributs, Null, Default, Extra, and have 3 options to choose, Primary, Index, and Unique.
I undertand for ID, its auto_increment in the drop down menu in extra, and its a primary. But thats about it.
Are all types except for Email VARCHAR?
Hope this is not too much to ask.
Thanks for your time.
Oliver
February 26th, 2009 at 1:47 am
Good posting.Do u want to see Auto Forum and Community ? u can visit my blog friend :D.ow yeah your blog has alread bookmarked by me
April 26th, 2009 at 5:52 am
Very well written post however, I would recommend that you turn the No Follow off in your comment section.
Keep up the good work.
June 24th, 2009 at 8:29 pm
Thanks a whole lot i find your tutorial helpful for a starter now i can learn my php peacefully . I Found many tutorials but yours had clarity and easy to follow In an hours time i was up and running.Many thanks.
July 11th, 2009 at 5:51 am
It was interesting. You seem very knowledgeable in ypour field.
September 2nd, 2009 at 11:16 am
First time checking out this blog, but I got to say I’ll probably be here more often
September 13th, 2009 at 7:44 am
I was hoping I could ask you a rhetorical question about yourself, would that be ok? Its always good to share a great post.
October 19th, 2009 at 9:26 am
It was interesting to browse trough
keep up the good work and thanks for sharing. I will be checking regulary now as the stuff here on your site looks to be very helpful. Good myspace stuff.
November 15th, 2009 at 10:31 am
Good stuff, bookmarked for further reading.
December 11th, 2009 at 6:21 pm
I normally don’t leave comments but I like this show sooo much! I bookmarked your site on dig!
December 19th, 2009 at 2:22 am
A mate encoraged me to read this site, nice post, interesting read… keep up the nice work!
December 19th, 2009 at 4:21 pm
This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article!
December 20th, 2009 at 7:07 am
compelling read. Have a extremely good month!
January 9th, 2010 at 6:22 am
Wonderful site, I really discovered it to be interesting. I’m looking forward to coming back once again to learn what is recent.
January 10th, 2010 at 9:45 am
Great looking Blog! Found it through Yahoo. Just as an FYI, it didnt display right when I opened it in the Opera Interet Browser.
January 25th, 2010 at 4:45 pm
I like what you have to say
February 5th, 2010 at 9:48 am
Hi sweetie, nice website! I really appreciate this article.. I was curious about this for a long time now. This cleared a lot up for me! Do you have a rss feed that I can add?
March 6th, 2010 at 6:01 am
Dreamweaver has been lately my personal goto application for years. I really do not know what I would undoubtedly do without having it. There were periods when I initially began using the software, and I believed it was way too complicated. Now I fly around it, and it has turn out to be a strong asset in my personal tool box. Nonetheless thank you for the content.
March 20th, 2010 at 4:15 am
Some of the images on your site look broken. You should probably fix them
March 25th, 2010 at 12:08 am
My blog very much like yours. But how do you avoid the many stupid user comments?
March 26th, 2010 at 9:39 am
Hi just thought i would tell you something.. This is twice now i’ve landed on your blog in the last 3 days searching for totally unrelated things. Spooky or what? If you wantto exchange the links with us please let me know.
March 29th, 2010 at 1:15 pm
I’m going to bookmark this blogg on Identica to get more views for you.
March 30th, 2010 at 6:48 am
I want to say – thank you for this!
April 28th, 2010 at 6:47 pm
howdy, I go over all your posts, keep them coming.
May 4th, 2010 at 12:49 am
Merci pour ce post intéressant. si vous continuer ainsi je vais devenir un lecteur fidéle
May 26th, 2010 at 11:00 am
I’ve have to advise you, u r friggin on. I reached this site from another hyperlink and am heavily interested in this topic and reading more. Do you mind if I quote to this article from my blog?
June 1st, 2010 at 8:24 am
You da man. Keep it rockin.