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.
I cannot find the download page – Please put a link somewhere
I agree I couldn’t find a dowload either and the email never sent to my email 🙁
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.
is this function specific to your shared hosting? should i ask my hosting for the correct one i should use?
thankyou
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!
in the form section of html file <form action="your_file.php" method="post
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!!
i´m having the same issue, the content does not show up in the email, i´m going crazy!
I too am having trouble with the content. It is not showing up in my e-mail. I am using Dreamweaver CS4.
Hi Nathaniel, Is there a fix for the no content showing up? Im using godaddy server. Do I need to link the php.ini?
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 🙂
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
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
EOD;
$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
Tom
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!
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 “relay-hosting.secureserver.net” 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!!
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
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!!
LuisRod, thank you! This resolved my issue.
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) { nm=val.name; 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’,’http://www.youtube.com/v/XsrRRklznj4′,’type’,’application/x-shockwave-flash’,’wmode’,’transparent’,’movie’,’http://www.youtube.com/v/XsrRRklznj4′ ); //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
by the way am using roundcube from 000webhost
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
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;
267
268 echo “$Result”;
269 ?>
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’];
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:
Navn:
Firma:
Adresse:
Post nr.:
By:
Email:
Telefon:
Pølsebar:
Københavnervogn:
Gasvogn:
Elvogn:
Fadølsanlæg:
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”;?>
I dont seem to have a download option…?
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]..
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!
I cannot find a download page to get the codes. HELP PLEASE
Nate :your 4 yEAR OLD php SCRIPT FOR EMAIL FORMS WAS FANTASTIC.nOW IF ONLY I CAN FIND THE ZIP/RAR FILES
(TUTVID SITE HAS CHANGED CONSIDERABLY SINCE THEN)
YOU CAN EMAIL ME AT [email protected] .COM WITH THE url OF THE FILES
aren’t the downloads available anymore?:(
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?
Loved this tutorial. Works perfectly! Thanks a lot! Now I’ll be going over to see the tutorial for validating the form.
Thanks,
Abdullah M.
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.
thanks
man!!!
Abel
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?
I have the same problem. Have you a solution? Mail: [email protected]
I have this problem too, has anyone found a solution?
Anyone have a fix for this problem? Please…?
Hey, i had some problems with my script if one of you could help me it would be greatly appericated.
————————————————————————————————————————————-
<?php
$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
EOD;
$headers = “From: $emailrn”;
$headers .= “Content=type: text/htmlrn”;
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<
————————————————————————————————————
Thanks guys!
Where’s the link to download the files please?
Nathan:
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.
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?
fixed it:-) forgot to replace $headers = “From: $email rn” with $headers = “From: $emailFieldrn”
some help here please. i changed the Email: $email to Email: $emailField and all but it still dont show me any content in the mail… anybody?
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!
where are the files to download on revised site?
hi
how can I download this tutorail
thanks
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].
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.
Hey will this work if i’m using a local server in my computer? Thanks
Nevermind, it worked, it just took its time to send the email 🙂
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!
Does anyone know how to add a spam protector (captcha) to this form? I am having a hard time with it.
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.
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?
thanks
I have found a FIX!!!
Use _REQUEST instead of the _POST method!
I received all filed info!
Request worked for me too! Thank you for this!
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 😀 🙁
<?php
/*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
EOD;
$Headers = “From: $emailrn”;
$Headers .= “Content-type: text/htmlrn”;
$success = mail ($webMaster, $emailSubject, $body, $Headers);
?>
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
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?
Thanks.
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.
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?
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?
Thanks,
Trevor
link availbe after login to gmail or other account
I loged in but I still dont see a download for this.. NO ANSWERS?
Please can someone help me find the down load page for the php scripting page
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!
For those looking for the link:
http://www.htmlgoodies.com/beyond/php/article.php/3855686
Where is de download link for the files?
can.t find download link for the PHP and HTML Docs
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.
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,
Emmanuel
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 https://get-accs.com/email-accounts/
I am trying to make contact form to work.
anyone able to help me see what is wrong.
Massage is a great way to relieve muscle pain, soreness, and tension. It doesn’t matter whether this pain was caused by physical or mental stress, the massage will work it for you.Visit body to body massage centres in hsr layout
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.
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
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
nice service provided by the spa
One of the oldest healing practices is massage. Massage was used to treat many ailments by ancient peoples such as the Ancient Greeks and Egyptians, Chinese, and Chinese. Visit Doorstep body massage service in Bangalore
We have consulted with our female clients and we are proud to introduce this feminine client-base type of massage.
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.