【发布时间】:2014-06-10 14:13:20
【问题描述】:
我需要什么:
- 当我提交表单时,邮件会发送给recipent。
我的问题:
- 提交表单时,表单提交正常,响应代码:200k,但未发送电子邮件。
这是我正在使用的代码:-
if(isset($_POST['submit']))
{
$to = $_POST['email'];
$from = "abc@gmail.com";
$subject = "subject";
$message = "<div style=\"background:red;height:100px;width:100px;display:block;\">dfsdf</div>";
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "From: $from\r\n";
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
}else{
echo "Add an email address";
}?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="testemail.php" method="post">
<input name="email" type="text" />
<input name="submit" type="submit" value="Submit">
</form>
</body>
</html>
错误日志:
HP Notice: Undefined variable: form in /var/www/index2.php on line 192
[Tue Jun 10 19:09:10.799088 2014] [:error] [pid 3588] [client 127.0.0.1:48078] PHP Notice: Undefined index: WRCF-Name in /var/www/asana/index2.php on line 246
[Tue Jun 10 19:09:10.799095 2014] [:error] [pid 3588] [client 127.0.0.1:48078] PHP Notice: Undefined index: WRCF-Email in /var/www/asana/index2.php on line 251
[Tue Jun 10 19:09:37.272245 2014] [:error] [pid 3545] [client 127.0.0.1:48096] PHP Notice: Undefined index: save-stuff in /var/www/asana/index2.php on line 123, referer: http://localhost/index2.php
sh: 1: /usr/sbin/sendmail: not found
sh: 1: /usr/sbin/sendmail: not found
sh: 1: /usr/sbin/sendmail: not found
sh: 1: /usr/sbin/sendmail: not found
sh: 1: /usr/sbin/sendmail: not found
sh: 1: /usr/sbin/sendmail: not found
安装发送邮件:
sudo apt-get install sendmail
Reading package lists... Done
Building dependency tree
Reading state information... Done
sendmail is already the newest version.
The following packages were automatically installed and are no longer required:
libfluidsynth1 libmad0 libmikmod2 libsdl-image1.2 libsdl-mixer1.2
libsdl1.2debian libwebp4 linux-headers-3.11.0-19
linux-headers-3.11.0-19-generic linux-image-3.11.0-19-generic
linux-image-extra-3.11.0-19-generic musescore-soundfont-gm sauerbraten-data
【问题讨论】:
-
你的邮件服务器日志告诉你什么?
-
检查日志并尝试 phpMailer 库
-
从本地机器发送这个?还是来自服务器?
-
本地 Smtp 或 senmail 是否安装在您正在测试的环境中?
-
您没有安装本地邮件服务器。即使不是 sendmail,其他“大”的(postfix、exim 等)也会创建一个 sendmail 符号链接。因为你根本没有 sendmail,所以你没有安装任何邮件服务器。