Build a PHP Script to Send Email – Dreamweaver Tutorial

Build a PHP Script to Send Email – Dreamweaver Tutorial

In the following tutorial we will start with a few html files – which are available for download here on the site – and we will build an Email Handling PHP script that sends info from your web form to your email! It is pretty easy PHP so enjoy learning and Have fun! I am using Dreamweaver CS3, but you can use pretty much any version of Dreamweaver, just follow closely and try not to make mistakes.

More from Nathaniel Dodson
The Extract Filter – Photoshop CS2
The Extract Filter In Photoshop CS2 Learn how to make and use...
Read More
Join the Conversation


  1. says: Bene_amin

    Note: most of these scripts use the mail() function – That does not work on our shared hosting (because we don’t have access to the php.ini file). Therefore they gave us their own function called :
    function authSendEmail($toaddress, $subject, $message) – We used that and it was dead easy.

    1. says: Maluguimpel

      is this function specific to your shared hosting? should i ask my hosting for the correct one i should use?

  2. says: SYAWEDIS

    Hey man, I don’t use dreamweaver I strictly use a text editor and when you talk about linking the html to the php file, you go into Design view and do it from there, leaving me clueless as to what I have to write into the Code.

    Can you explain how I would target the php file in Code format?

    Great tutorial btw!

  3. says: Tammy

    Hey there Nathaniel!  Thanks for the instructions…I went over them several times and am still having trouble with the content not showing up in the email…the fields show up but the answers that the client enter do not…could you tell me what I might be missing?  Thanks!!

  4. says: MikeMcC

    I too am having trouble with the content.  It is not showing up in my e-mail.  I am using Dreamweaver CS4.

  5. says: Spaceboy

    Hi Nathaniel, Is there a fix for the no content showing up? Im using godaddy server. Do I need to link the php.ini?

  6. says: LuisRod

    guys. I emailed Nathaniel about this issue. And he said.
    “Hey   Luis   ,
    No problem at all, man! Glad you tweeted over to me so I saw it :PFor some servers in the EOD part it shouldn’t be: Email: $email , but:Email: $emailField etc etc.And in the headers part you have to change $headers = “From: $email rn”,to: $headers = “From: $emailFieldrn”Note: There are also issues with Yahoo! and GoDaddy servers. If you areusing their hosting try contacting them and see if they have any answers foryou.”
    hope you guys can get it to work 🙂

    1. says: Steven

      I’m on an Apache/Linux server, and I made the change of Email: $email to:Email: $emailField etc. etc., and also $headers = “From: $emailFieldrn and it is all working perfectly.  Don’t know why it worked for you in the tutorial.  Thanks for the fix.  Steven

    2. Hay would you have a look at my code, something is wrong, when i hit send i get a lot of code come up


      Email: $emailField

      Name: $nameField

      Phone Number: $phoneField

      Budget: $budgetField

      Number of Travelers: $travelersField

      Comments: $commentsField

      Newsletter: $newsletterField


      $headers = “From: $emailFieldrn”;
      $headers = “Content-type: text/htmlrn”;
      $success = mail($webMaster, $emailSubject, $body, $headers);

      /* Results rendered as HTML */

      $theResults = <


      im guessing i have miss something out but i just can’t work it out.

      hope you can help


      1. says: Jacoba

        Hi Tomasz,
        did you include the following part:
        $Headers = “From: $emailrn”;
            $Headers .= “Content-type: text/htmlrn”;
            $success = mail ($webMaster, $emailSubject, $body, $Headers);

        In the video, Nathaniel specifically mentiones the second line, which makes sure the code got ‘translated’ into text (instead of code)

        Hope this solves your problem!

  7. says: Anonymous

    I tried this PHP code, and when I receive the email, there is no content and the email appears to come from an “unknow sender”.  I have a shared server with GoDaddy, and they indicated that I need to include “” somewhere in the PHP code, but I’m a rookie with PHP and not sure how to do this.  I’m also not sure if this is the problem that is causing the labels to be sent without the content or data??  Please help as I’d love to get this working.  Thanks!!

  8. says: Xmalunda

    i tried the code designed my template using FW cs4 but when i put the file and click submit it shows me the code and NO email is sent please help 

  9. says: Jacoba

    Hi Nathaniel,
    I really like your tutorials and builded all my websites based upon them 😉
    But now I have the same ‘problem’ as mentioned below, I cannot find the document htmltophp. Can you help me with that?
    Thank you!!

  10. says: kamil

    hello i dont know why mine is not working here the code
    K1K!<?php/* Subject and Email Variables */ $emailSubject = 'Contact ME!'; $webMaster = '[email protected]'; /* Gathering Data Variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $subjectField = $_POST['subject']; $messageField = $_POST['message']; $body = <<<EODName: $name Email: $email Subject: $subject Message: $message EOD; $headers = “From: $emailrn”; $headers  .= “Content-type: text/htmlrn”; $success = mail($webMaster, $emailSubject, $body,    $headers); /* Result rendere as HTML */ $theResults = <<< EOD  K1K!body,td,th { font-family: “Droid Serif”, serif;}h1,h2,h3,h4,h5,h6 { font-family: Michroma, sans-serif;}function MM_validateForm() { //v4.0  if (document.getElementById){    var i,p,q,nm,test,num,min,max,errors=”,args=MM_validateForm.arguments;    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);      if (val) {; if ((val=val.value)!="") {        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.n';        } else if (test!='R') { num = parseFloat(val);          if (isNaN(val)) errors+='- '+nm+' must contain a number.n';          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');            min=test.substring(8,p); max=test.substring(p+1);            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.n';      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.n'; }    } if (errors) alert('The following error(s) occurred:n'+errors);    document.MM_returnValue = (errors == '');} }         Time(GMT):obj=new Object;obj.clockfile=”free002-black.swf”;obj.TimeZone=”WET”;obj.width=150;obj.height=150;obj.wmode=”transparent”;showClock(obj);Latest Videos:        AC_AX_RunContent( ‘width’,’292′,’height’,’250′,’src’,’′,’type’,’application/x-shockwave-flash’,’wmode’,’transparent’,’movie’,’′ ); //end AC code  Recent Tweets:new TWTR.Widget({  version: 2,  type: ‘profile’,  rpp: 2,  interval: 30000,  width: 250,  height: 300,  theme: {    shell: {      background: ‘#333’,      color: ‘#fff’    },    tweets: {      background: ‘#333’,      color: ‘#fff’,      links: ‘#4aed05’    }  },  features: {    scrollbar: false,    loop: false,    live: false,    behavior: ‘all’  }}).render().setUser(‘K1KXD’).start(); Home Images Videos Servers Staff Donate Contact Us                          Thank you for contacting me, i shall get back to you as soon as possible.Copyright © 2010-2012 Kamil Pietrecki(K1K), LLC. All Rights Reserved.EOD;echo “$theResults”;?>

    it send the email but it doesn’t show the information or the sender email

  11. says: Kaamil331

    i was reading some suggestion my new code
    K1K!<?php/* Subject and Email Variables */ $emailSubject = 'Contact ME!'; $webMaster = '[email protected]'; /* Gathering Data Variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $subjectField = $_POST['subject']; $messageField = $_POST['message']; $body = <<<EODName: $nameField Email: $emailField Subject: $subjectField Message: $messageField EOD; $Headers = “From: $emailFieldrn”; $Headers  .= “Content-type: text/htmlrn”; $success = mail($webMaster, $emailSubject, $body, $Headers); /* Result rendere as HTML */

    still doesn’t work it send the email but the information doesn’t appear

  12. says: Javier3446

    Hey guys a lil help would be nice am getting an error:

    Parse error: syntax error, unexpected $end in /home/content/35/7697835/html/sendemail.php on line 270

    and all my code ends at line 269 i don’t have aline 270

    266 EOD;        
    268 echo “$Result”;
    269 ?>

  13. says: Croger

    Hey Nathaniel, 
    How do I fix this error :   Fatal error: Function name must be a string in /home/a3757721/public_html/contactformprocess.php on line 10

    in line 10  I have this:
     Gathering Data Variables */ $emailField = $_POST [’email’];  (line10) $nameField = $_POST [‘name’]; $phoneField = $_POST [‘phone’];     $budgetField = $_POST [‘budget’]; $travelersField = $_POST [‘travelers’]; $commentsField = $_POST [‘comments’]; $newsletterField = $_POST [‘newsletter’];

  14. says: Mabiom92

    Hi 🙂

    I saw your tutorial and i like it!
    When I receive the email there is no information inside – exept:Tilbagemelding på email:

    Tilbagemeldning på telefon:




    Post nr.:









    Slushice maskine:

    Popcorn maskine:

    Leje dato fra:

    Leje dato til:

    Forventet antal gæster:

    Beskrivelse af arrangement:

    Hope you can help me! <?php/* Subject and Email Variables */    $emailSubject = 'Forespørgsel på arrangement!';    $webMaster = '[email protected]';    /* Gathering Data Variables */    $tilbagemelding_emailField = $_POST['tilbagemelding_email'];    $tilbagemelding_telefonField = $_POST['tilbagemelding_telefon'];    $navnField = $_POST['navn'];    $firmaField = $_POST['firma'];    $adresseField = $_POST['adresse'];    $postnrField = $_POST['postnr'];    $byField = $_POST['by'];    $emailField = $_POST['email'];    $telefonField = $_POST['telefon'];    $poelsebarField = $_POST['poelsebar'];    $koebenhavnervognField = $_POST['koebenhavnervogn'];    $gasvognField = $_POST['gasvogn'];    $elvognField = $_POST['elvogn'];    $fadoelField = $_POST['fadoel'];    $slushiceField = $_POST['slushice'];    $popcornField = $_POST['popcorn'];    $lejefraField = $_POST['lejefra'];    $lejetilField = $_POST['lejetil'];    $gaestField = $_POST['gaest'];    $beskrivelseField = $_POST['beskrivelse'];        $body = <<<EODTilbagemelding på email: $tilbagemelding_email Tilbagemeldning på telefon: $tilbagemelding_telefon Navn: $navnField Firma: $firmaField Adresse: $adresseField Post nr.: $postnrField By: $byField Email: $emailField Telefon: $telefonField Pølsebar: $poelsebarField Københavnervogn: $koebenhavnervognField Gasvogn: $gasvognField Elvogn: $elvognField Fadølsanlæg: $fadoelField Slushice maskine: $slushiceField Popcorn maskine: $popcornField Leje dato fra: $lejefraField Leje dato til: $lejetilField Forventet antal gæster: $gaestField Beskrivelse af arrangement: $beskrivelseField EOD;    $headers = “From: $emailFieldrn”;    $headers .= “Content-type: text/htmlrn”;    $success = mail($webMaster, $emailSubject, $body, $headers);    /* Results rendered as HTML */    $theResults = <<<EOD        Velkommen til Bjarnes Pølser                #container {                width:1000px;                height:auto;                margin:auto;            }            #header {                width:800px;                height:150px;                margin-left:42;                margin-right:auto;            }            #sidebar {                float:right;                width:200px;                height:500px;                margin-left:auto;                margin-right:auto;            }            #main {                width:800px;                height:500px;                background-image:url(images/Main.png);                background-repeat:repeat-y;                margin-left:42;                margin-right:auto;                    }            #footer {                width:800px;                height:60px;                margin-left:42;                margin-right:auto;            }                                                                                                                    Vi takker for din forespørgsel. Din forespørgsel vil blive besvaret hurtigst mulig!                                                             EOD;echo “$theResults”;?>

  15. says: Ediesweedie

    does network solutions use different setting for this.  i have used your php form for several websites, but for some reason, gathering the data variables isn’t working.  the html email comes through with no info and no email address?  HELP!  [email protected]..

  16. says: Anne

    As stated in a previous comment from another user, I also needed to take out the word field for my form to work properly but in general I found your tutorials really easy to follow and I just wanted to say a massive thank you!

  17. says: Ronb

    I did this tutorial and successfully ONCE got the form to work. Now I’m trying it again, using the code that WORKED (this is not yelling, only putting emphasis on the word), and following all the same steps. But when I get down to the EOD; close before echo, it doesn’t show code coloring, which I understand that it means it’s NOT working.

    Any suggestions? Also, how do you get the checkboxes to download in the email results?

  18. says: Abelpede

    Sweet tutorial brother!…. it worked like a charm!….do you mind creating a second part of this tutorial but with a upload file field on this form?….I had been searching all around for this …and is all useless!!….i kinda like the way you explained things!!!…. i don’t know nothing about php and i just code my first page thanks to you man!  but i kinda lost  on how to make this field work with the form….and received a file(image) attached to the email that this form is producing.



  19. says: TlFord

    I enjoyed the tutorial, but I do have one question. The form is sending the email, but the info in the form does not appear. How do I fix that?

  20. Hey, i had some problems with my script if one of you could help me it would be greatly appericated.
    $emailSubject = 'Inquiry From Website';
    $webMaster = '[email protected]';

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];
    $coqField = $_POST['coq'];
    $sendField = $_POST['send'];

    $body = <<<EOD

    Name: $name
    Email: $email
    Phone: $phone
    Subscription: $send
    Inquiry: $coq
    $headers = “From: $emailrn”;
    $headers .= “Content=type: text/htmlrn”;
    $success = mail($webMaster, $emailSubject, $body, $headers);

    $theResults = <<
    Thanks guys!

  21. says: MO

    Great PHP script! After correcting the EOD and $headers lines, everything worked fine; however, I’m getting two messages sent for each completed form: One from the originating email account and one from my hosting service. The email from sent from my hosting service has blank fields (i.e., it doesn’t capture the information). I’m attempting to troubleshoot that and is probably an issue with my hosting service. Thanks again. Your site is a God send and a tremendous resource to the uninitiated.

  22. says: Hunky Dory

    Thank you Nathaniel, your tutorials are always the best! Everything works with this script for me, except that I cannot reply directly but instead need to open new mail and copy paste the address of sender. How do I fix that?

  23. says: Tdog

    Nothing comes back in the email. No data? How do you fix this? I did my own PHP script based on my fields but did it the same way as this tutorial. It should have data. HELP!

  24. says: Katrina

    I have tried everything and I can’t get the email address field to work. It comes up as Email: when it sends me the form in my email address. It also doesn’t show the email address of who it is from. Everything else in the form and submission part worked. If anyone can help me with the Email address field I would greatly appreciate it. Please email me at [email protected].

  25. says: HTTR

    This was a very effective tutorial and worked great. The only problem I have is that I would like the form fields to clear after submit/send button is pressed. When hitting the back button from the Thank you page, the entered info is still present, very annoying. Is there a way to have the info clear automatically after submission other than hitting the refresh button at the top of the page? Any help would be appreciated.

      1. says: Emma

        out of interest, how long did the message take to send? Also, what local server were you using and did you copy the tutorial directly? I am trying to do the same thing on a local server (XAMPP) and it doesn’t seem to be working – so far…thanks!

  26. says: csmith

    I hope this is still monitored…
    I haven’t received the email that I have sent from the form submission.
    I received the html window showing the “thank you” message… but no email ever arrives.
    Any help would be appreciated – I can send or past the code if requested.

    1. says: csmith

      Strike the above, I have now received the email (changed email address… must be a server issue with the other one) HOWEVER, now I have the same issue as others seem to have. The content that was entered into the form was not received … exception is the comment area… strange! Any help out there?

  27. says: Sasi spenzer

    hey guys this is my script..can you find any error in these code?? when i click my submit button it displaying the $body variable data..ohhh i m going crazy 😀 🙁

    /*my variables*/
    $webSubject = 'myscripting';
    $webMaster = '[email protected]';
    /* getting data to the form*/

    $nameField = $_POST['name'];
    $emailField = $_POST['email'];
    $phoneField = $_POST['phone'];

    $body = <<<EOD

    Name: $email
    Email: $email
    Phone: $phone

    $Headers = “From: $emailrn”;
    $Headers .= “Content-type: text/htmlrn”;
    $success = mail ($webMaster, $emailSubject, $body, $Headers);


  28. says: lisa

    Hi Nathaniel, thanks for this tutorial, my first php experience! You explain things very well and I got my form to work. I have one little problem and am wondering if you know how to fix it….

    since I have the form up on my website I am getting emails from [email protected] (hostpapa is my server) and all the answers to the email fields are the same; 1. So I get:

    name: 1
    email: 1
    message: 1
    What does this mean? Is this spam or did I do something wrong?
    I have tried the form and get the right answers that I filled out, so it works, but these hostpapa emails are annoying. I have contacted them and they don’t know what it is and think it might be my form…
    I hope you can help me

    1. says: Shealtiel

      Hello Lisa. Do you have the php code that Nathaniel wrote? Because I looked for the download page that was mentioned in the video, but I wasn’t able to find it. I think the file is no longer available or has been moved. Could you help me out on this?

  29. says: Julie

    It seems to work on the website but I do not get the email. I’ve gone over it and over it many times and I think it is perfect.

  30. says: CarlM

    Hi guys, I followed thru with the tutorial. I have my own form, I didn’t use the downloadable one. So, when I click my ‘submit’ button, the Mail icon hops on my dock. Is the ‘submit’ button on the form suppose to link to the php? Or is there any missing code I have to write in the php file?

  31. says: Trevor

    I was able to tweek the PHP code with everyone’s comments and got it to work. My email came through finally with all the content.

    Here is my problem. My form has 3 fields for individuals to attach images before they send it to me. After someone submits their content, my email shows all the content and the ONLY file names of the attach images instead of the images themselves. What do I need to do to fix this problem?


  32. says: Emma

    The code works fine except the email does not send. I have used a ymail account and a gmail account, neither of which have worked. Any help would be much appreciated as I am going crazy!! Thanks!

  33. Pingback: Divx Download
  34. Pingback: теилим
  35. Pingback: Directory
  36. Pingback: satta matka
  37. Pingback: Agen Bandarq
  38. Pingback: yandex ankara
  39. Pingback: economics tuition
  40. Pingback: ICQ Chat
  41. Pingback: London or UK
  42. Pingback: Akantor Webdesign
  43. Pingback: auto transport
  44. Pingback: pizza dog
  45. Pingback: para kazanmak
  46. Pingback: ankara escort
  47. Pingback: para para dinle
  48. Pingback: rhodium
  49. Pingback: joe de saram
  50. Pingback: rhodium
  51. Pingback: openhaard
  52. Pingback: kimsin sen
  53. Pingback: cul
  54. says: Linda

    I need help. I am getting the email body text but the variables are not showing up in my email? anyone able to help me see what is wrong. I see I am not the only one with this problem.

  55. Pingback: Cheap
  56. says: Emmanuel

    Hi Nathaniel
    I have been following you since 2008, I was in a better place then doing web in Sydney.
    I am now in France and have to use a DW trial in order to code. Which gives you an idea on my lack of fund to have a subscription.
    I am trying to make contact form to work.
    I am using some template from one website which I coupled with another.
    I have managed before to make it connect with the script before, even though the information was not getting to my Email.
    However I can’t get the script to connect and move to the html “sent” page.
    Can you please help over the next 48 hours? Please don’t have a go at me.
    Thanks a lot,

  57. says: Ben Suite

    Hi, I think everyone has heard of business marketing, so this is very cool service that allows you to buy Email account, a very cool site where you can find many different and more important – safe accounts that you can buy with no problem at a very good price

  58. says: B2B massage

    The gentle touch turn off, she may also make herself appear to tempt you. Her body is so appealing that it will be difficult to turn away from her. Start by slowly moving her around and then rubbing your body together.

  59. Aside from loosened up muscles, your temper will likewise improve, hence furnishing you with an unwavering discernment. A decent outlook will hoist your temperament, assisting you with managing viably during upsetting circumstances. A body back rub will get inscription, causing you to have outlook on yourself; it additionally hugely affects great wellbeing. Visit body massage at home bangalore

  60. says: spa69

    Do you research about the spa service providers to ensure that you get the best possible service in Bangalore. You want a provider that offers safe and effective body to body and erotic massages. Choose a provider who has a team of experienced therapists. You can provide the best service by understanding the needs of clients. Visit body massage in hsr layout

  61. Our soothing Massage with hot oil and slight touches can calm you down and release your anxiety and depression. Rising stress/anxiety directly affects your sleep and causes insomnia among thousands of people, leaving you deprived of sleep and alone, wandering in the dark with sleepless nights.

Leave a comment
Leave a comment

Your email address will not be published. Required fields are marked *