<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Onyx Design Weblog &#187; PHP</title>
	<atom:link href="http://www.onyx-design.net/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onyx-design.net</link>
	<description>A weblog about webdesign, webdevelopment, css, php and other webrelated topics.</description>
	<lastBuildDate>Thu, 03 Jun 2010 15:34:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to e-mail a HTML form with PHP</title>
		<link>http://www.onyx-design.net/php/how-to-e-mail-a-html-form-with-php/</link>
		<comments>http://www.onyx-design.net/php/how-to-e-mail-a-html-form-with-php/#comments</comments>
		<pubDate>Sun, 13 Jan 2008 09:43:58 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.onyx-design.net/weblog2/featured/how-to-e-mail-a-html-form-with-php/</guid>
		<description><![CDATA[HTML forms are easy to make, but sending a form as an e-mail is a lot harder. There are many ways to do this, but I only review one in this article. HTML combined with a little PHP scripting.
First of all
Make sure that your host supports PHP. You can ask your host or make a [...]]]></description>
			<content:encoded><![CDATA[<p><acronym title="HyperText Markup Language">HTML</acronym> forms are easy to make, but sending a form as an e-mail is a lot harder. There are many ways to do this, but I only review one in this article. <acronym title="HyperText Markup Language">HTML</acronym> combined with a little <acronym title="Pre-Hypertext Processing">PHP</acronym> scripting.<span id="more-31"></span></p>
<h3>First of all</h3>
<p>Make sure that your host supports <acronym title="Pre-Hypertext Processing">PHP</acronym>. You can ask your host or make a file named phpinfo.php containing only this: <code><br />
&lt;?php<br />
phpinfo();<br />
?&gt;</code></p>
<p>Put that file on your server. If you see something like <a href="http://www.clickpress.de/phpinfo.php" rel="nofollow" >this</a> your host has <acronym title="Pre-Hypertext Processing">PHP</acronym> support.</p>
<h3>The <acronym title="HyperText Markup Language">HTML</acronym> part</h3>
<p>Now we have to make the <acronym title="HyperText Markup Language">HTML</acronym> form. I expect that most of you will know how to make so I will not talk about it thoroughly. For example, we will use this simple <acronym title="HyperText Markup Language">HTML</acronym> form:</p>
<p><code>&lt;form action="mail.php"<br />
method="post"&gt;<br />
First name:<br />
&lt;input type="text" name="firstname"&gt;<br />
&lt;br&gt;<br />
Last name:<br />
&lt;input type="text" name="lastname"&gt;<br />
&lt;input type="submit" value="Submit"&gt;<br />
&lt;/form&gt;</code></p>
<p>Pay attention to the <em>action-attribute</em> and the <em>method-attribute.</em> The <em>action</em> determines to which file the data must sended and the <em>method</em> determines how it must be send; either post or get (in the url, like index.php?lang=en&amp;page=home). We will choose for post, as you don&#8217;t won&#8217;t passwords or other private information to show up in the url. An live example of this form can be found <a href="http://www.onyx-design.net/weblog2/wp-content/uploads/2008/01/form.html">here</a>.</p>
<h3>The <acronym title="Pre-Hypertext Processing">PHP</acronym> part</h3>
<p>As you can see, the <acronym title="HyperText Markup Language">HTML</acronym> form refers to a file name <em>mail.php</em>. Now we have to make this file. Here is the whole script:<br />
<code>&lt;?php<br />
// Name and E-mail of the Recipient<br />
$name_recipient = "Onyx";<br />
$email_recipient = "info@onyx-design.net";</code></p>
<p><code>// The name and email of the sender<br />
$name_sender = $_POST['lastname'];<br />
$email_sender = "noreply@onyx-design.net";</code></p>
<p><code>// The subject of the email<br />
$subject = "How to send a mail form by <acronym title="Pre-Hypertext Processing">PHP</acronym>";</code></p>
<p><code>// the headers of the email (you can also add a CC or BCC this way)<br />
$headers = "From: ".$name_sender." &lt;".$email_sender."&gt;\r\n";<br />
$headers .= "<acronym title="Multipurpose Internet Mail Extension">MIME</acronym>-Version: 1.0\r\n";<br />
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";<br />
$headers .= "Reply-To: ".$name_sender." &lt;".$email_sender."&gt;\r\n";</code></p>
<p><code>// the message<br />
$message = "<br />
-------------------------------------<br />
How to send a mail form with <acronym title="Pre-Hypertext Processing">PHP</acronym><br />
-------------------------------------<br />
This form was sent to you by:</code></p>
<p><code>First Name:".$_POST['firstname']."<br />
Last Name:".$_POST['lastname']."</code><br />
<code><br />
";<br />
// Ad &lt;br&gt; to the message<br />
$bericht = nl2br($message);</code></p>
<p><code>// Send the mail<br />
mail($email_recipient, $subject, $message, $headers);</code><code></code></p>
<p><code>?&gt;</code></p>
<h4>$_POST['...']</h4>
<p>The data which is sent by the <acronym title="HyperText Markup Language">HTML</acronym> form can be recovered by <acronym title="Pre-Hypertext Processing">PHP</acronym> via the $_POST. If you look back to the <acronym title="HyperText Markup Language">HTML</acronym> code, you see that the <em>&lt;input&gt;</em> has a <em>name-attribute, </em>for example: <em>name=lastname</em>. You can retrieve the data of that field with this <acronym title="Pre-Hypertext Processing">PHP</acronym>-code: $_POST['lastname']. That is what I did in this script.</p>
<h4>nl2br()</h4>
<p>This function inserts <acronym title="HyperText Markup Language">HTML</acronym>-line breaks into the message. The function is <acronym title="eXtensible HyperText Markup Language">XHTML</acronym> valid (&lt;br /&gt; instead of &lt;br&gt;).</p>
<h4>mail()</h4>
<p>The <em>mail()-function</em> has four parameters: <em>to, subject, message, headers.</em> More information about the <em>mail()-function </em>can be found <a href="http://nl3.php.net/function.mail" rel="nofollow"  target="_blank">here</a>.</p>
<h3>Done!</h3>
<p>Now you now how to make a mail-form. If you have anything to ask feel free to place a comment.</p>]]></content:encoded>
			<wfw:commentRss>http://www.onyx-design.net/php/how-to-e-mail-a-html-form-with-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
