Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a <strong>tested</strong> version with the <code>From:</code> now showing in the appropriate location of the Email.</p> <ul> <li>Quick note: There was two seperate header bodies which broke up your code.</li> </ul> <p>One under <code>$subject</code> and the other over <code>$messagetext</code>. All are inside one body of headers now.</p> <p>Plus, you had <code>$headers = 'From: '.$EmailAddress.'/r/n';</code> which is invalid.</p> <p>This should have read as <code>$headers = 'From: '.$EmailAddress.'\r\n';</code> with <code>\</code> instead of <code>/</code>.</p> <p>More on the <code>mail()</code> function can be read by visiting PHP.net on <a href="http://php.net/manual/en/function.mail.php" rel="nofollow"><code>mail() - here.</code></a></p> <h2>Working code</h2> <pre><code>&lt;?php $url = 'ThankYou.php'; $ContactName = $_POST['ContactName']; $EmailAddress = $_POST['EmailAddress']; $PhoneNumber = $_POST['PhoneNumber']; $Message = $_POST['Message']; $PracticeName = $_POST['PracticeName']; $to = "email@example.com"; $subject = 'Someone sent you a contact request'; // message $messagetext = '&lt;html&gt;&lt;body&gt;'; $messagetext .= ' &lt;p&gt;Website Form Submit&lt;/p&gt;'; $messagetext .= ' &lt;table&gt;'; $messagetext .= ' &lt;tr&gt;&lt;td align="right"&gt;Name:&lt;/td&gt;&lt;td&gt;'.$ContactName.'&lt;/td&gt;&lt;/tr&gt;'; $messagetext .= ' &lt;tr&gt;&lt;td align="right"&gt;Email Address:&lt;/td&gt;&lt;td align="left"&gt;'.$EmailAddress.'&lt;/td&gt;&lt;/tr&gt;'; $messagetext .= ' &lt;tr&gt;&lt;td align="right"&gt;Phone Number:&lt;/td&gt;&lt;td align="left"&gt;'.$PhoneNumber.'&lt;/td&gt;&lt;/tr&gt;'; $messagetext .= ' &lt;tr&gt;&lt;td align="right"&gt;Practice Name:&lt;/td&gt;&lt;td align="left"&gt;'.$PracticeName.'&lt;/td&gt;&lt;/tr&gt;'; $messagetext .= ' &lt;tr&gt;&lt;td align="right"&gt;Message:&lt;/td&gt;&lt;td align="left"&gt;'.$Message.'&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;'; $messagetext .= ' &lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'; // To send HTML mail, the Content-type header must be set $headers = "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; $headers .= "From: $EmailAddress" . "\r\n" . "Reply-To: $EmailAddress" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); // Mail it mail($to, $subject, $messagetext, $headers); //echo $message; echo '&lt;META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'"&gt;'; //echo "Success"; // my testing method ?&gt; </code></pre> <hr> <h2>Additional options:</h2> <p>To make sure someone fills in all the fields and not send mail unless they do, then you can use the following and make sure you remove the <code>&amp;nbsp;</code> in your <code>&lt;textarea name="Message"...</code> because that is considered as input.</p> <pre><code>if(!empty($_POST['EmailAddress']) &amp;&amp; (!empty($_POST['ContactName'])) &amp;&amp; (!empty($_POST['PhoneNumber'])) &amp;&amp; (!empty($_POST['PracticeName'])) &amp;&amp; (!empty($_POST['Message'])) ) { mail($to, $subject, $messagetext, $headers); //echo $message; // echo '&lt;META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'"&gt;'; echo "Success"; } else { echo "Mail failed. All fields must be filled."; } </code></pre> <p>There are more improvements that can be done, for instance Email validation such as <code>FILTER_VALIDATE_EMAIL</code>.</p> <p>Example:</p> <pre><code>$email = $_POST['EmailAddress']; if(empty($_POST['EmailAddress']) || !filter_var($EmailAddress, FILTER_VALIDATE_EMAIL)) { die("Please enter a valid email"); } </code></pre> <p>More on <code>FILTER_VALIDATE_EMAIL</code> can be found on the PHP.net Website </p> <ul> <li><strong><a href="http://php.net/manual/en/filter.filters.validate.php" rel="nofollow">http://php.net/manual/en/filter.filters.validate.php</a></strong></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload