我正在努力为这个HTML代码创建PHP。我是一名前端设计师,而不是后端任何帮助?这是它应该是基本的,但我已经尝试过让它工作似乎每次都让它变得更糟......
HTML CODE
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Your Name">
<label></label>
<input name="email" type="email" required placeholder="Your Email">
<label></label>
<input name="tel" type="tel" placeholder="Your Contact Number">
<label></label>
<select name="treatment">
<option value="">Select...</option>
<option value="">Anti-Wrinkle Injections</option>
<option value="">Dermal Fillers</option>
<option value="">The Vampire Facelift</option>
<option value="">Other Treatments</option>
</select>
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
PHP代码
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'email';
$subject = 'Email Inquiry';
$body = "From: {$name}\n E-Mail: {$email}\n Message:\n {$message}";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email! You will now be redirected to the Home Page.</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message again.</p>';
}
}
?>
答案 0 :(得分:2)
这就是PHP应该是:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'an email address';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";?>
它是一个?不是/在最后
我刚刚使用这个php测试了代码,它运行正常。
答案 1 :(得分:0)
试试这个。
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website';
$to = 'an email address';
$subject = 'Email Inquiry';
$body = "From: ".$name."<br/>E-Mail: ".$email."<br/> Message:<br/>". $message;
?>