저는 PHP로 초보자이며 정규식을 사용하여 유효성을 검증 한 후 PHP 스크립트를 사용하여 입력 한 정보를 이메일 주소로 보내고 "감사합니다 "페이지. 나는 다음 페이지에있는 튜토리얼을 따르려고 노력했다. http://myphpform.com/php-form-tutorial.php문의 양식 PHP를 사용하여 이메일을 통해 보내십시오.
나는 유니폼 서버를 사용하여 테스트 서버를 설정하고 메일 서버가 작동하는 mailtest.php 파일을 사용하여 설정했다. 하지만 내 양식으로 작업 할 PHP 스크립트를 얻을 수 없으므로 누군가가 제공 할 수있는 조언을 정말 감사하게 생각하십시오.
HTML - 페이지에서 : http://www.plymouthparentpartnership.org.uk/index.php?p=32_3
<span class="title">Parent Request for Involvement in Parenting Programmes</span>
<p>If you are a <span style="font-weight: bold;">Parent</span>, please complete this form to request a Parenting Programme.</p>
<p>If you are a <span style="font-weight: bold;">Professional</span>, please use the <a href="http://www.plymouthparentpartnership.org.uk/index.php?p=32_4" title="Professional Form to request Parenting Programme">Professional Form</a> to request a Parenting Programme.</p>
<div style="WIDTH: 75%" class="box-round-corner">
<form action="parent-p-programme.php" method="post">
<div>
<div>
<div>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>
<td colspan="2"> <span class="error">* required field.</span></td>
</tr>
<tr>
<td>Name:</td>
<td>
<input type="text" name="name" size="35" /> <span class="error"> *</span></td>
</tr>
<tr>
<td style="VERTICAL-ALIGN: top">Telephone Number or<br />
Mobile number if main number:</td>
<td>
<input type="text" name="tel" size="35" /> <span class="error"> *</span></td>
</tr>
<tr>
<td>Mobile Number:</td>
<td>
<input type="text" name="mobile" size="35" /></td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<input type="email" name="email" size="35" /></td>
</tr>
<tr>
<td>Course Required:</td>
<td>
<select name="course">
<option selected="selected">Please select course</option>
<option>Incredible Years</option>
<option>Strengthening Families 10-14 years</option>
</select> <span class="error"> *</span></td>
</tr>
<tr>
<td style="VERTICAL-ALIGN: top">Date of Birth of<br />
Child/Young Person:</td>
<td>
<input type="text" name="dob" size="35" /> <span class="error"> *</span></td>
</tr>
<tr>
<td style="VERTICAL-ALIGN: top">Additional Information:</td>
<td>
<textarea name="info" rows="5" cols="32"></textarea></td>
</tr>
</tbody>
</table>
<p>We aim to respond to your enquiry within 2 working days.</p>
<p>
<input type="submit" value="Send Request" />
<input type="reset" value="Clear Form" /></p></div> </div> </div>
</form></div>
PHP 스크립트
<?php
/* Parent request for Parenting Programme */
/* Set e-mail recipient */
$myemail = "[email protected]"; // dummy email
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name"); // required
$tel = check_input($_POST['tel'], "Enter your telephone number or mobile number if this is your main number"); // required
$mobile = check_input($_POST['mobile']);
$email = check_input($_POST['email']);
$course = check_input($_POST['course'], "Select course required"); // required
$dob = check_input($_POST['dob'], "Enter young persons date of birth"); // required
$info = check_input($_POST['info']);
/* If tel no is not valid show error message */
if (!preg_match("/([0-9 ]{6})?([0-9]{6})/", $tel))
{
$tel = '';
}
/* Validate mobile no (optional) */
if (!preg_match("/([0-9 ]{6})?([0-9]{6})/", $mobile))
{
$mobile = '';
}
/* If e-mail is not valid show error message (optional) */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
$email = '';
}
/* Email Message */
$message = "Request for $course
Name: $name
Tel No: $tel
Mobile: $mobile
Email: $email
Course: $course
Young Person's Date of Birth: $dob
Additional information:
$info
End of message
";
/* Send message using mail() function */
mail($myemail, $message);
/* Redirect to thank you page */
header('Location: 32_5.html');
exit();
?>
<?php
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
완료 필드 후 팝업 페이지를 제출하기 위해 "감사"어디에서 필드를 인식하는 것 채워지지 않지만 유효성 검사가 제대로 작동하지 않는 것 같습니다. 내가 로컬에서 테스트 할 때
는 양식 제출
<span class="title">Parenting Programme Request</span>
<p>Your request for a Parenting Programme was sent.</p>
<p>We aim to respond to your request within 2 working days.</p>
PHP 스크립트는 어떤 이메일을 전송하지 후에에게 페이지 감사드립니다. 저녁 내내 그것을 보았지만, 내가 뭘 잘못하고 있는지 보지 못했습니다. 그러므로 누군가에게 제공 할 수있는 도움이나 조언이 있으면 미리 알려 주시기 바랍니다.
변수를 인쇄하여 실제로 전자 메일과 다른 항목을 전달하고 있음을 알 수 있습니까? – Guardanis
메일 서버가 작동합니까? 'mail()'과 함께 매우 간단한 이메일을 보낼 수 있습니까? 또한이 함수를 배우는 것만으로도 PHPMailer와 같은 다른 것을 사용하는 것이 좋습니다. – James
@sue D, 당신은 PHP에 익숙하지 않다고 설명했듯이 모든 기능 개념을 사용하는 이유는 간단합니다. 참고 사이트와 마찬가지로 간단하게 만들 수도 있습니다. – SagarPPanchal