- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 php 邮件功能,可以发送包含联系表内容的电子邮件。但是当我在我的网站上发送这封电子邮件时。输入的电子邮件地址不是 from header ,而是 username@srv30.000webhost.com,我不知道为什么。我的 php 邮件功能如下。
$email 是用户输入的邮箱。
编辑:主题:你好评论X-PHP-脚本:kwp.host22.com/form_action.php for 78.147.187.64消息 ID:<20131124204151.478EC28021@srv30.000webhost.com>日期:2013 年 11 月 24 日星期日 15:41:51 -0500 (EST)发件人:a5485011@srv30.000webhost.com返回路径:a5485011@srv30.000webhost.comX-OriginalArrivalTime:2013 年 11 月 24 日 20:41:52.0292 (UTC) FILETIME=[9B09B640:01CEE955]
完整的 php 脚本:
$name = ($_GET['Name']) ? $_GET['Name'] : $_POST['Name'];
$email = ($_GET['Email']) ?$_GET['Email'] : $_POST['Email'];
$phone = ($_GET['Phone']) ?$_GET['Phone'] : $_POST['Phone'];
$comment = ($_GET['Comment']) ?$_GET['Comment'] : $_POST['Comment'];
// flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
// Simple server side validation for POST data, of course, you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$comment) $errors[count($errors)] = 'Please enter your comment.';
// if the errors array is empty, send the mail
if (!$errors) {
// recipient
$to = '<example@example.com>';
// sender
$from = $name . ' <' . $email . '>';
// subject and the html message
$subject = 'Comment from ' . $name;
$message = '
<!DOCTYPE html>
<html>
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Phone</td><td>' . $phone . '</td></tr>
<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
// send the mail
$result = @mail($to, $subject, $message, $from);
// if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
// else if GET was used, return the boolean value so that
// ajax script can react accordingly
// 1 means success, 0 means failed
} else {
echo $result; }
// if the errors array has values
} else {
// display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo '<a href="contact.php">Back</a>';
exit;}
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
$headers .= 'Reply-To: ' .$email . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
@mail($to, $subject, $message, $headers);
if ($result) return 1;
else return 0;}
我是 PHP 的新手,因此我们将不胜感激。谢谢
最佳答案
我相信这条线
$result = @mail($to, $subject, $message, $from);
应该固定为这个
$result = sendmail($to, $subject, $message, $from);
并将您的发送邮件功能更改为此
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' .$from . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
@mail($to, $subject, $message, $headers);
if ($result) return 1;
else return 0;
}
此处您使用的是 $email,但也许您应该使用 $from。您的函数接受 $to、$subject、$message、$from。
此外,您也许应该稍微更改一下代码
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' .$from . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){
return 1;
}
return 0;
}
sendmail 是一个用于发送电子邮件的 unix 应用程序二进制文件。用 PHP 编写您自己的 sendmail 函数不会做任何事情。我相信 PHP 邮件功能在 linux 上默认使用 sendmail,在 windows 上,您需要配置 SMTP。但是在发送您的电子邮件时,这不是问题所在。也许你应该重命名函数,这样你就不会无意中混用这些东西。
这里也重写了整个代码,也许你可以学到一两件事:)
$post = false;
// flag to indicate which method it uses. If POST set it to 1
if (isset($_POST['Name'])) {
$post = true;
}
$name = (isset($_GET['Name'])) ? $_GET['Name'] : $_POST['Name'];
$email = (isset($_GET['Email'])) ? $_GET['Email'] : $_POST['Email'];
$phone = (isset($_GET['Phone'])) ? $_GET['Phone'] : $_POST['Phone'];
$comment = (isset($_GET['Comment'])) ? $_GET['Comment'] : $_POST['Comment'];
// Simple server side validation for POST data, of course, you should validate the email
if (!$name) {
$errors[] = 'Please enter your name.';
}
if (!$email) {
$errors[] = 'Please enter your email.';
}
if (!$comment) {
$errors[] = 'Please enter your comment.';
}
// if the errors array is empty, send the mail
if (count($errors) == 0) {
// recipient
$to = 'example@example.com';
// sender
$from = $name . ' <' . $email . '>';
// subject and the html message
$subject = 'Comment from ' . $name;
$message = '<!DOCTYPE html>
<html>
<head></head>
<body>
<table>
<tr><td>Name</td><td>' . $name . '</td></tr>
<tr><td>Email</td><td>' . $email . '</td></tr>
<tr><td>Phone</td><td>' . $phone . '</td></tr>
<tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr>
</table>
</body>
</html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: ' . $from . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$mailSuccess = mail($to, $subject, $message, $headers);
// if POST was used, display the message straight away
if ($post) {
if ($mailSuccess) {
echo 'Thank you! We have received your message.';
} else {
echo 'Sorry, unexpected error. Please try again later';
}
// else if GET was used, return the boolean value so that
// ajax script can react accordingly
// 1 means success, 0 means failed
} else {
echo (int)$mailSuccess;
}
// if the errors array has values
} else {
// display the errors message
foreach ($errors as $error) {
echo $error . '<br/>';
}
echo '<a href="contact.php">Back</a>';
}
关于PHP 邮件功能未正确设置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20180626/
我在让“@header”或任何其他@规则在ANTLR中工作时遇到麻烦。具有非常基本的语法,如下所示: grammar test; options { language = CSharp2;
我对来源和寄宿有疑问 我有一个ajax页面“Page A”,它将称为ajax提要“Page B” 我看到来自ajax调用的“页面B”的请求 header 具有源“http://mydomain.com
我在 pandas 中使用了数据透视表并获得了所需的数据框格式,但现在我有两行标题。数据透视表后的结果数据框如下: scenario Actual Plan
我在 pandas 中使用了数据透视表并获得了所需的数据框格式,但现在我有两行标题。数据透视表后的结果数据框如下: scenario Actual Plan
我想在主机将它们发送到网络之前修改数据包头(IP 头、TCP 头)。 例如,如果我使用 firefox 进行浏览,那么我想拦截所有来自 firefox 的数据包并修改 IP/TCP header ,然
我的 header 内容被包装到#header 中,但是当我设置边框显示结构时,它显示我的#header 的内容出现在#header 本身之后。可能是什么问题?这是我的代码: #header { bo
我是一名 Web 开发人员,使用过 PHP 和 .NET。有一年多的 Web 工作经验,我一直无法彻底了解浏览器缓存功能,希望这里的 Web Gurus 可以帮助我。我心中的问题是: 浏览器实际上是如
伙计们,我有一个问题,我不知道如何在一个 header 中连接多个 header ,我们称它为“主 header ”并使用该 header 中的函数,例如 // A.h #include class
我有一个包含 SOAP 消息的 XMLHTTPRequest。 我想添加用于标识消息并将由 C# Web 服务使用的 guid。 GUID 的目标是识别特定用户,并应护送所有用户请求以在服务器上进行身
我一直在阅读粘性标题,这是我目前所发现的。第一个粘性 header 效果很好,但是当它遇到第一个 header 时,我如何向上滚动第一个 header 并使第二个 header 卡住? http://
我想将当前基于 TableView 的数据网格转换为新的 UICollectionView 类。 这就是我当前的网格的样子: 我的网格有两个标题: 年份(2006a、2007a 等)和 类型(“收入”
我目前正在使用 Apollo 服务器。我正在尝试在响应 header 中设置一个属性。并且此属性是从客户端 graphQL 请求 header 中检索的。 我在网上查了一下。并看到了诸如使用插件或扩展
我的 Controller 的方法需要设置一个标题,例如X-Authorization .创建新对象( store Action )后,我执行转发以显示新创建的对象( show Action ): $
我正在研究一些关于 VLAN 的事情,发现了 VLAN 标签 和 header 。 如果我们有标准 802.3 以太网帧 的 MTU(1518 字节), header 802.3 中包含什么? 另外,
我是放心和 Java 的新手,我正在尝试做一个非常基本的测试来检查 API 的响应是否为 200 ok。 谁能告诉我我需要在下面的脚本中更改什么才能传递多个 header Id、Key 和 ConId
在我的项目中,我需要知道 zlib header 是什么样的。我听说它相当简单,但我找不到 zlib header 的任何描述。 例如,它是否包含魔数(Magic Number)? 最佳答案 zlib
我正在使用 JMeter 测试 HTTP 服务器,该服务器接受并验证 APIKey 并在成功时返回一个有时限的 token 。如果我有 token ,我想发送一个 token ;如果没有,我想发送一个
以太网 header 是什么样的? 是吗: 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|
我们的应用程序支持 CORS 配置 header 。我在两个不同的主机上分别配置了 testApp。两种设置都相互独立工作。host1 上的应用程序配置有 CORS header Access-Con
tlhelp32.h 不包含 windows.h 本身是有原因的吗?我一直在与大量的编译器错误作斗争,因为我在包含 tlhelp32.h 之后包含了 windows.h。这是设计决定还是出于什么原因?
我是一名优秀的程序员,十分优秀!