我只需要在提交表单时将邮件发送给收件人。我的表单提交的响应代码为200k,但邮件未送达。我已经安装了sendmail。
sendmail.php代码:
if(isset($_POST['submit']))
{
$subject = $_POST['subject'];
$to = "abc@gmail.com";
$from = $_POST['email'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
mail ($to, $subject,$msg, $headers);
echo "sent";
}
在php.ini文件中安装了邮件服务器:
[mail function]
; Setup for Linux systems
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = me@myserver.com
答案 0 :(得分:2)
mail ($to, $subject,$msg, $headers);
echo "sent";
而不是这个,首先检查邮件是否已发送
$mail=mail ($to, $subject,$msg, $headers);
if($mail){
echo "sent";
}else{
echo "failed.";
}
实际上你可以知道你的邮件是否正常工作
如果它不起作用。问题可能出在localhost中的SMTP设置
如果未使用
启用,则启用php中的错误ini_set('display_errors',1);
答案 1 :(得分:0)