【发布时间】:2016-12-01 00:21:05
【问题描述】:
所以我正在为一位客户创建一个网站,他希望我创建一个联系我们页面,现在我试图在电子邮件中说明:“$name $name2 和他的email 是 $from。\n 他想说的消息是 $message 的主题,而消息是 $message2" 帮助?
我的html代码:
<form action="contactus.php" method="post">
<div class="form-group">
<label for="Subject">Subject*</label>
<input name="subject" class="form-control" id="subject1" placeholder="Subject">
</div>
<label for="sabject">Why do you want to contact us?</label>
<br>
<select name="select">
<option value="General Inquiry">General Inquiry</option>
<option value="hampion Guide Request">Champion Guide Request</option>
<option value="League of Legends Show(s) Request">League of Legends Show(s) Request</option>
<option value="Podcast - League of Legends">Podcast - League of Legends</option>
</select>
<label for="fname">First Name*</label>
<input type="text" name="firstname" class="form-control" id="namef" placeholder="First Name">
<label for="lname">Last Name</label>
<input type="text" name="lastname" class="form-control" id="namel" placeholder="Last Name">
<label for="email_adress">Email Adress*</label>
<input type="email" name="email_adress" class="form-control" id="email_adress" placeholder="Email Adress">
<label for="message">Message*</label>
<input name="message2" class="form-control" id="message" placeholder="message">
<input style="margin-top: 50px;" value="Send Form" name="submit" type="submit">Submit</button>
</form>
php:
<html>
<head>
<title> PHP script</title>
</head>
<body>
<?php
$to ="sudaiguy1@gmail.com";
$from = isset($_POST['email_adress']) ? $_POST['email_adress'] : '';
$email_subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$message = isset($_POST['select']) ? $_POST['select'] : '';
$message2 = isset($_POST['message2']) ? $_POST['message2'] : '';
$name = isset($_POST['firstname']) ? $_POST['firstname'] : '';
if (empty($name)||empty($from))
{
echo "Name and email are mandatory!";
exit;
}
elseif (empty($email_subject)||empty($message)) {
echo "Your email or subject are blank, please write something in them";
exit;
}
elseif (empty($name)||empty($message2)) {
echo "Your name or message are empty";
exit;
}
$name2 = isset($_POST['lastname']) ? $_POST['lastname'] : '';
$email_from = "sudaiguy1@gmail.com";
$body = $_POST['You have been contacted by $name $name2 and his email is $from. \n The message he wanted to say was in the subject of $message and the message is $message2'];
$headers = "From: $body";
mail($to , $email_subject , $body ,$headers);
?>
</body>
</html>
我的问题是它说的是未识别的变量索引或类似的东西
【问题讨论】:
-
“我的 PHP 有问题”... PHP 在哪里...?
-
您能提供给我们您的 PHP 吗?这将有助于了解您如何获取表单值
-
是的,它说我没有正确缩进,所以我不得不重新缩进 sry
-
使用 xampp localhost thingie 添加了 php 脚本 BTW im
-
$body = $_POST['You have been contacted by....,为什么包裹在$_POST中?