我试图通过填写联系表单来发送电子邮件。我的html表单和php文件都包含在下面。填写表格后,它会通知我电子邮件已发送。但是,我从未收到过电子邮件;我无法弄清楚我做错了什么。
这是我的html表单:
<div class="row" style="padding-top:27px">
<div class="large-6 column">
<form action="mail.php" method="POST" data-abide>
<div class="name-field">
<label>Your name*</label>
<input type="text" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
</div>
<div class="large-6 column">
<!-- <label> Message </label>
<textarea class="error" placeholder="Message..." id="info" class="message" name="message" cols="70" rows="60" size="90" requi></textarea><br>-->
<label> Message </label>
<textarea class="error" placeholder="Message..." ></textarea>
<small class="error">Invalid entry</small>
<div>
<input style="float:right;" type="submit" value="Submit">
<img style="visibility: hidden;">
</div>
</form>
这是我的php文件:
<?php
$to = "education@arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
更新文件:
HTML:
<div class="name-field">
<label>Your name*</label>
<input type="text" name="name" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" name="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" name="subject" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
<!-- End Contact Form -->
</div>
PHP:
<?php
$to = "education@arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
答案 0 :(得分:1)
您的所有输入字段均未与name
相关联,因此您可能会在POST
中获取空数据。 $_POST['email']
中的“电子邮件”值指的是输入字段name
。
具体而言,您没有从表单中收到电子邮件地址,因此该电子邮件不会发送给任何人。
例如,您需要:
<input type="email" name="email" required>
答案 1 :(得分:0)
mail()的第四个参数是附加标题。这是你的“FROM”信息应该去的地方。
参考这里: http://php.net/manual/en/function.mail.php
应该去那里。
这是一个例子
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();