Dreamweaver Forms with PHP posting to MySQL table, emailing response

Posted on 2007-11-29
Last Modified: 2013-12-12
I have 3 questions.  I have designed and tested a php form in Dreamweaver CS3.  This form will post to MySQL database perfectly.

However, i want to script an email back to the user acknowledging the information entered in the form being submited.  I also want to be able to email myself the form information.

What is the best way to acheive this?
Question by:andrewl77

Accepted Solution

simonkin earned 125 total points
ID: 20372558
Hi, Try this....

	// Set the carriage return (End of Line)



	// Set the email from name

	$fromName = "Your Name";


	// Set the from email

	$fromEmail = "";


	// Set your domain

	$domain = ""


	// Set the message subject

	$subject = "Your email subject";


	// Set the admin email

	$emailAdmin = "";


	// Set the user email - you'll have to get this from the form post

	$userEmail = "";


	// Set the email body (Just an example, set your own body to suit where variables are the variables from your form)

	$body = "Your email introduction..." . $eol . $eol;

	$body .= "Variable 1 = $variable1" .$eol;

	$body .= "Variable 2 = $variable2" .$eol;

	$body .= "Variable 3 = $variable3" .$eol;

	$body .= "Variable 4 = $variable4" .$eol;

	$body .= "Variable 5 = $variable5" .$eol;


	// Set the mime boundary

	$mime_boundary = md5(time());


	// Set the headers

	$headers = "From: $fromName <$fromEmail>" . $eol;

	$headers .= "Reply-To: $fromName <$fromEmail>" . $eol;

	$headers .= "Return-Path: $fromName <$fromEmail>" . $eol;

	$headers .= "Message-ID: <" . time() . "-$domain>" . $eol;

	$headers = "X-Mailer: PHP v" . phpversion() . $eol;


	// Send the email as HTML

	$headers .= "Content-Type: multipart/mixed; boundary=\"" . $mime_boundary . "\"" . $eol . $eol;


	// Open the first part of the mail

	$msg = "--" . $mime_boundary . $eol;


	// Define a different MIME boundary for this section

	$htmlalt_mime_boundary = $mime_boundary."_htmlalt"; 


	// Setup for text OR html -

	$msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol;


	// HTML Version

	$msg .= "--" . $htmlalt_mime_boundary . $eol;

	$msg .= "Content-Type: text/html; charset=iso-8859-1" . $eol;

	$msg .= "Content-Transfer-Encoding: 8bit" . $eol . $eol;

	$msg .= $body . $eol . $eol;

	// Close the html/plain text alternate portion

	$msg .= "--" . $htmlalt_mime_boundary . "--" . $eol . $eol;


	// Finish with two eol's for better security.

	$msg .= "--" . $mime_boundary . "--" . $eol . $eol;  


	// Send the email

	mail($emailUser, $subject, $msg, $headers);

	mail($emailAdmin, $subject, $msg, $headers);


Open in new window

LVL 17

Assisted Solution

nplib earned 125 total points
ID: 20376823
i like phpmailer

it's very simple to use.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now