我正在尝试使以下表格起作用。当用户提交表单时,我希望能够通过电子邮件从文本字段和单选按钮发送信息。我还希望页面在表单提交后重定向到“谢谢”页面。按照目前的情况,页面重定向但没有发送电子邮件。这是我目前拥有的:
HTML:
Name: <input type="text" id="name" name="name" />
Date: <input type="text" id="date" name="date" />
Job description: <input type="text" id="job" name="job" />
<label for="yes">Yes</label>
<input type="radio" id="Yes" name="q1" value="Yes"/>
<label for="no">No</label>
<input type="radio" id="No" name="q1" value="No"/>
<label for="yes">Yes</label>
<input type="radio" id="Yes" name="q2" value="Yes"/>
<label for="no">No</label>
<input type="radio" id="No" name="q2" value="No"/>
<label for="yes">Yes</label>
<input type="radio" id="Yes" name="q3" value="Yes"/>
<label for="no">No</label>
<input type="radio" id="No" name="q3" value="No"/>
<input type="radio" id="Maybe" name="q3" value="Maybe"/>
<label for="why">Why? (please state)</label><input type="text" id="why" name="why"/>
<input type="submit" id="message_submit" class="submit-button"/>
</form>
PHP
<?php
$toaddress = "example@example.com";
$subject = "Subject";
$email = "sender@example.com";
$url = 'thankyou.php';
$msg = "$name\n";
$msg.= "$date\n";
$msg.= "$job\n";
$msg.= "$q1\n";
$msg.= "$q2\n";
$msg.= "$q3\n";
$msg.= "$why\n";
$mailheaders = "From: $email\n";
$mailheaders .= "To: recipient@example.com\n";
$mailheaders .= "Content-Type: multipart/mixed; \n";
mail($toaddress, $subject, $msg, $mailheaders);
if($sent)
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>