Send a confirmation email using php
<p>I am using the script below to return an email with the submitted fields to my email address. </p>

<p>I have recently found the need to have a confirmation email sent to who ever submitted the form in the first place but am unsure on how to alter the script. I basically need it to say something like "Dear $name, Thanks for contacting us....".</p>

<p>Please can someone help?</p>

<pre><code>&lt;?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Website Enquiry';

// Your email address. This is where the form information will be sent.
$emailadd = 'myemail@myemail.co.uk';

// Where to redirect after form is processed.
$url = 'thanks.php';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// --------------------------Do not edit below this line--------------------------
$text = "WEBSITE ENQUIRY:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key =&gt; $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j &gt;= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i &lt;= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '&lt;META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'"&gt;';
?&gt;
</code></pre>

<p>The script allows for any form element to be sent in the email without the need of including it within the php script.</p>

<p>The email address is collected in the html</p>

<pre><code>&lt;span class="input"&gt;
  &lt;input type="text" name="Email" id="Email"/&gt;
  &lt;/span&gt;
</code></pre>

<p>and the name...</p>

<pre><code>&lt;span class="input"&gt;
    &lt;input type="text" name="Name" id="Name" /&gt;
 &lt;/span&gt;
</code></pre>

<p>Many thanks</p>

<p>Craig</p>
