Php 在本地主机上正确发送邮件,但在上载到服务器时未发送
我的页面中有一个简单的邮件功能。我使用测试邮件服务器工具在本地系统上检查它,它正在发送邮件。但当我上传文件到服务器时,它并没有发送文件 以下是电子邮件代码:Php 在本地主机上正确发送邮件,但在上载到服务器时未发送,php,email,mail-server,Php,Email,Mail Server,我的页面中有一个简单的邮件功能。我使用测试邮件服务器工具在本地系统上检查它,它正在发送邮件。但当我上传文件到服务器时,它并没有发送文件 以下是电子邮件代码: if($_POST['name']) { $subject = "Message from website"; $name = $_POST['name']; $email = $_POST['email']; $number = $_POST['number']; $txt = " Name : "
if($_POST['name'])
{
$subject = "Message from website";
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$txt = " Name : " . $name . " \r\n Email : " . $email . " \r\n Contact No. : " . $number;
$headers = 'From:' . $name . "\r\n";
$mail=mail('xyz@gmail.com', $subject, $txt, $headers);
if($mail)
{
echo "Thank You!";
}
if(!$mail)
{
echo "failed";
}
}
else
echo "no values entered";
我在本地主机上看到“谢谢”消息。但当我上传到服务器时,它会显示“失败”消息
请帮忙
提前谢谢 在编码中添加以下行
`$this->load->library('email');
$config['protocol'] = 'mail';
$config['charset'] = 'utf-8';
$this->email->initialize($config);
$this->email->set_mailtype('html');'
邮件功能
$msg = "<html>
<body>
User Contact Details
<table>
<tr><td>Name:</td><td>".$_POST['name']."</td></tr>
<tr><td>Mobile:</td><td>".$_POST['mobile']."</td></tr>
<tr><td>Email :</td><td>".$_POST['email']."</td></tr>
</table>
</body>
</html>
";
$this->load->library('email');
$config['protocol'] = 'mail';
$config['charset'] = 'utf-8';
$this->email->initialize($config);
$this->email->from('From email id');
$this->email->to('$_POST['email']');
$this->email->subject('Subject of ur email id');
$this->email->message($msg);
$this->email->set_mailtype('html');
if($this->email->send())
{
echo 'Thank you';
}
else
{
echo "failed";
}
您使用的是哪台服务器?实际上我的上级正在上传到服务器。我不知道他使用的是哪台服务器。它在localhost中为我工作。这是否意味着代码正常?请尝试最后打印错误;而不是echo失败;您可以获得更多关于失败原因的详细信息Yes code似乎还可以,服务器检查问题sendmail或postfix是否安装在服务器上谢谢bansi,Chetan Ameta,我会检查这些内容