【发布时间】:2014-03-14 22:04:27
【问题描述】:
谁能帮我弄清楚为什么这个电子邮件表单不会发送电子邮件?我和 IT 部门核实过,他们说它所在的服务器的电子邮件功能已打开,并且托管的其他网站可以发送电子邮件。表单正在提取数据......它只是不会发送电子邮件。我觉得这将是一件非常明显的事情,导致电子邮件无法发送,我只是看不到它。
<?php
require 'topInclude.php';
?>
<div id="contentwrapper">
<div id="waiverContent">
<div id="dvdContentRight">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var defaultMessage = "Please provide a brief description of how you plan to adapt the messaging and/or graphic design.";
$("#myTextArea").focus(function(){
if( $(this).val() == defaultMessage){
$(this).val("");
}
}).blur(function(){
if( $(this).val() == "" ){
$(this).val(defaultMessage);
}
}).val(defaultMessage);
});
</script>
<?php
if (isset($_POST['submit'])) {
$errors = array(); // Initialize the errors array
if (empty($_POST['company_name'])) {
$errors[] = 'Please enter your first name.';
} else {
$Cn = filter_var($_POST['company_name'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}
if (empty($_POST['contact_name'])) {
$errors[] = 'Please enter your name.';
} else {
$ln = filter_var($_POST['contact_name'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}
if (empty($_POST['address'])) {
$errors[] = 'Please enter your work address.';
} else {
$add = filter_var($_POST['address'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}
if (empty($_POST['email'])) {
$errors[] = 'Please enter your email address.';
} else {
$e = filter_var($_POST['email'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}
if (empty($_POST['comments']) || ($_POST['comments'] == 'Please provide a brief description of how you plan to adapt the messaging and/or graphic design.')) {
$errors[] = 'Please provide a brief description of how you plan to adapt the messaging and/or graphic design.';
} else {
$co = filter_var($_POST['comments'], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
}
if (!empty($_POST['phone'])) {
$p = $_POST['phone'];
} else {
$p = '';
}
if (empty($_POST['checkbox'])) {
$errors[] = 'You must agree to the Permission To Use / Reproduce conditions.';
} else {
$cb = $_POST['checkbox'];
}
if (empty($errors)) {
$body = "The information sent is as follows:\n\n Company Name: $Cn \n Contact Name: $ln \n Work Address: $add \n Phone: $p \n Email: $e \n I agree to terms: $cb \n\n Comments: $co";
mail ('xxxxxxxx@gmail.com', 'W.E. Can Quit DVD Request', $body, 'From: '.$e);
echo '<div id="email"><div id="emailSent">
<h1>Thank you!</h1>
<p>Your request has been sent.</p>
</div>';
echo '<div id="emailSentImg"><img src="images/emailSent.jpg" /></div></div>';
} else { //Report any collected errors in the errors array.
echo '<div id="emailNotSent">
<h1>Error!</h1><br />
<p>The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><br /><p>Please use the \'back\' button in your browser and try again.</p>
</div>';
} // Ends the empty errors array if.
} else { // Form has not been submitted; display the form.
$errors = NULL;
?>
这是电子邮件表格:
<h2>Order Your DVD</h2>
<div id="dvdForm">
<form name="form" id="form" method="POST" action="<?php echo $PHP_SELF;?>">
<table width="550px">
<tr>
<td valign="top">
<label for="company_name" class="formText">Company Name:</label>
</td>
<td valign="top">
<input type="text" name="company_name" maxlength="50" size="45" value="<?php if (isset($_POST['company_name'])) echo $_POST['company_name']; ?>">
</td>
</tr>
<tr>
<td valign="top">
<label for="contact_name" class="formText">Contact Name:</label>
</td>
<td valign="top">
<input type="text" name="contact_name" maxlength="50" size="45" value="<?php if (isset($_POST['contact_name'])) echo $_POST['contact_name']; ?>">
</td>
</tr>
<tr>
<td valign="top">
<label for="address" class="formText">Work Address:</label>
</td>
<td valign="top">
<input type="text" name="address" maxlength="50" size="45" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>">
</td>
</tr>
<tr>
<td valign="top">
<label for="phone" class="formText">Phone Number:</label>
</td>
<td valign="top">
<input type="text" name="phone" maxlength="12" size="45" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>">
</td>
</tr>
<tr>
<td valign="top">
<label for="email" class="formText">Email Address:</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="45" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>">
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<textarea id="myTextArea" rows="4" cols="37" name="comments" value="<?php if (isset($_POST['comments'])) echo $_POST['comments']; ?>"></textarea>
</td>
</tr>
<tr>
<td valign="top">
<label for="checkbox">
I agree to all of the terms set
out in the <span class="italics">Permission To <br />
Use / Reproduce</span> conditions on
the left side of this page.</label>
</td>
<td valign="top">
<input type="checkbox" name="checkbox" value="Agreed">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
</div>
<?php } ?>
</div>
</div>
</div>
<?php
require 'bottomInclude.php';
?>
【问题讨论】:
-
当您调用
mail()时,SMTP 服务器的响应是什么? -
您可以尝试将gmail地址切换到另一个吗? Gmail 对从 PHP 发送的电子邮件存在一些问题——如果它们没有被静默丢弃,它们通常会以垃圾邮件告终。看看它是否适用于 Yahoo / Hotmail / 等。
-
@andrewsi:我尝试过使用三个不同的电子邮件地址:Gmail、Hotmail 和我们的工作电子邮件。
-
@keicea - 好的。然后下一步是检查来自
mail()的返回值。当您调用mail()时,它会返回什么? -
@David:我不确定。我无权访问服务器。我将文件提供给我们的 IT 部门,然后他们上传。