我的php邮件脚本存在问题,我似乎无法找到它的根源。对不起,如果这是一个愚蠢的问题,但我刚开始使用php。
我在第86行遇到语法错误“$ email_message”这里是完整的PHP脚本:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "office@medicaepv.ro";
$email_subject = "Cerere Programare";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['nume']) ||
!isset($_POST['prenume']) ||
!isset($_POST['telefon']) ||
!isset($_POST['adresa']) ||
!isset($_POST['email'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['nume']; // required
$last_name = $_POST['prenume']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telefon']; // required
$comments = $_POST['textarea']; // not required
$age = $_POST['varsta']; // not required
$adresa = $_POST['adresa']; //not required
$sex = $_POST['sex']; //not required
$region = $_POST['judet']; //required
$city = $_POST['oras']; //required
$departament = $_POST['departament']; //required
$date = $_POST['data']; //required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Nume: ".clean_string($first_name)."\n";
$email_message .= "Prenume: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telefon: ".clean_string($telephone)."\n";
$email_message .= "Varsta: ".clean_string($age)."\n";
$email_message .= "Sex: ".clean_string($sex)."\n";
$email_message .= "Adresa: ".clean_string($adresa)."\n";
$email_message .= "Judet: ".clean_string($region)."\n";
$email_message .= "Localitate: ".clean_string($city)."\n"
$email_message .= "Departament: ".clean_string($departament)."\n";
$email_message .= "Data: ".clean_string($date)."\n";
$email_message .= "Mesaj: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
这是表单html:
</div>
<div class="content">
<div class="container padd-top padd-bottom">
<div class="text-center">
<h2>Formular Programare</h2>
</div>
<form action="formular.php" method="POST" class="about-form info-form">
<div class="info-heading-icon">
<h4>Date Personale</h4>
</div>
<ul class="row info">
<li class="col-sm-4">
<span class="form-title">Nume</span>
<input type="text" name="nume" class="form-part" />
</li>
<li class="col-sm-4">
<span class="form-title">Prenume</span>
<input type="text" name="prenume" class="form-part" />
</li>
<li class="col-sm-4">
<span class="form-title">Varsta</span>
<input type="text" name="varsta" class="form-part" />
</li>
<li class="col-sm-4">
<span class="form-title">Sex</span>
<span class="info-holder">
<select class="form-part" name="sex">
<option>-Masculin-</option>
<option>-Feminin-</option>
</select><span class="info-arrow"> </span></span>
</li>
<li class="col-sm-8">
<span class="form-title">Adresa</span>
<input type="text" name="adresa" class="form-part" />
</li>
<li class="col-sm-4">
<span class="form-title">Judet</span>
<span class="info-holder">
<select class="form-part" name="judet">
<option>-Bucuresti Sector 1-</option>
<option>-Bucuresti Sector 2-</option>
<option>-Bucuresti Sector 3-</option>
<option>-Bucuresti Sector 4-</option>
<option>-Bucuresti Sector 5-</option>
<option>-Bucuresti Sector 6-</option>
<option>-Ilfov-</option>
<option>-Altul-</option>
</select><span class="info-arrow"> </span></span>
</li>
<li class="col-sm-4">
<span class="form-title">Localitate</span>
<span class="info-holder">
<select class="form-part" name="localitate">
<option>-Bucuresti-</option>
<option>-Chitila-</option>
<option>-Voluntari-</option>
<option>-Mogososoaia-</option>
<option>-Altul-</option>
</select> <span class="info-arrow"> </span></span>
</li>
<li class="col-sm-4">
<span class="form-title">Telefon</span>
<input type="tel" name="telefon" class="form-part" />
</li>
<li class="col-sm-4">
<span class="form-title">Email</span>
<input type="email" name="email" class="form-part" />
</li>
</ul>
<div class="info-heading-icon two">
<h4>Date Programare</h4>
</div>
<ul class="row info">
<li class="col-sm-4">
<span class="form-title">Departament</span>
<span class="info-holder">
<select class="form-part" name="departament">
<option>-Endocrinologie-</option>
<option>-Dermatologie-</option>
<option>-Nutritie-</option>
<option>-Diabet-</option>
<option>-Gastroenterologie-</option>
<option>-Investigatii de Laborator-</option>
</select> <span class="info-arrow"> </span> </span>
</li>
<li class="col-sm-4">
<span class="form-title">Data Programarii</span>
<input type="text" name="data" class="form-part date-pick" />
</li>
</ul>
<div class="info-heading-icon three">
<h4>Cu ce te putem ajuta?</h4>
</div>
<ul class="row">
<li class="col-sm-6">
<span class="form-title">Problema Ta</span>
<textarea name="textarea" class="form-part info-message"></textarea>
</li>
</ul>
<div class="text-left">
<input type="submit" class="btn btn-submit" value="Trimite!" />
</div>
<div class="g-recaptcha" data-sitekey="6LexXiEUAAAAAPmMR_MYL6sDrjOvVZqWaXemb9dK"></div>
</form>
</div>
</div>
请询问您是否还需要其他任何东西!
谢谢!
答案 0 :(得分:1)
在
后忘记了分号;
$email_message .= "Localitate: ".clean_string($city)."\n"
以后请查看PHP Parse/Syntax Errors; and How to solve them? 。
编辑:Tobias F. said:您应该使用支持语法突出显示的IDE或编辑器,或使用PHP Code Checker等在线服务。