简体   繁体   中英

Php form submitting to email

I am trying to take input from a form and email the results to me. I would like to format the email to look identical to what the customer sees when they are filling out the form (or very similar) I am having difficulties in trying to get this accomplished. Any help would be greatly appreciated.

Here is my form data

<form id="ContactKathryn" name="ContactKathryn" method="post" action="sendform/sendtokathryn.php">    
<table width="60%" border="0" cellpadding="2px" style="position:relative; left:20%">
<tr>
<td width="25%" align="right">Name:</td>
<td width="75%" align="left"><input name="ContactName" type="text" size="40" maxlength="100" /></td>
</tr>
<tr>
<td align="right">Email Address:</td>
<td align="left"><span id="sprytextfield1">
<input name="EmailAddress" type="text" id="EmailAddress" size="40" maxlength="150" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td align="right">Phone Number:</td>
<td align="left"><span id="sprytextfield2">
<label for="PhoneNumber"></label>
<input name="PhoneNumber" type="text" id="PhoneNumber" maxlength="15" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td align="right">Practice Name:</td>
<td align="left"><input name="PracticeName" type="text" size="40" maxlength="100" /></td>
</tr>
<tr>
<td align="right">Message:</td>
<td align="left"><textarea name="Message" cols="40" rows="10">&nbsp;</textarea></td>
</tr>
<tr>
<td align="center" width="25%"></td>
<td align="center" width="75%"><input name="SubmitForm" type="submit" id="SubmitForm" onclick="MM_popupMsg('Are you sure you would like to submit this form?\r');return document.MM_returnValue" value="Submit Form" /><input type="reset" name="ResetForm" id="ResetForm" value="Reset Form" /></td>
</table>
</form>

and this is my PHP code:

<?php
// Where to redirect after form is processed. 
$url = 'http://www.mydomain.com';

// multiple recipients
$to  = '123456@gmail.com'; // note the comma

// subject
$subject = 'Someone sent you a contact request';

// message
$message = '<html><body> ';
$message = 'MIME-Version: 1.0' . "\r\n";
$message = 'Content-type: text/html; charset=iso-8859-1';
$message = '  <p>Kathryn, someone sent you an email from the website</p>';
$message = '    <table>';
$message = '        <tr><td>Name:</td><td>'%$ContactName%'</td></tr>';
$message = '        <tr><td align="right">Email Address:</td><td align="left">'%$EmailAddress%'</td></tr>';
$message = '        <tr><td align="right">Phone Number:</td><td align="left">'%$PhoneNumber%'</td></tr>';
$message = '        <tr><td align="right">Practice Name:</td><td align="left">'%$PracticeName%'</td></tr>';
$message = '        <tr><td align="right">Message:</td><td align="left">'%$Message%'</textarea></td></tr>';
$message = '  </table></body></html>'; 

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


// Mail it
mail($to, $subject, $message, 'From: '.$EmailAddress.'', $headers);
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'
?>

The only thing I receive in the email when someone submits this form is: </table></body></html>

Concatenate your message strings:

// message
$message = '<html><body> ';
$message .= '  <p>Kathryn, someone sent you an email from the JanusDentalAdvisors&acute; website</p>';
$message .= '    <table>';
$message .= '        <tr><td>Name:</td><td>'.$ContactName.'</td></tr>';
$message .= '        <tr><td align="right">Email Address:</td><td align="left">'.$EmailAddress.'</td></tr>';
$message .= '        <tr><td align="right">Phone Number:</td><td align="left">'.$PhoneNumber.'</td></tr>';
$message .= '        <tr><td align="right">Practice Name:</td><td align="left">'.$PracticeName.'</td></tr>';
$message .= '        <tr><td align="right">Message:</td><td align="left">'.$Message.'</textarea></td></tr>';
$message .= '  </table></body></html>'; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM