邮件功能在PHP中不起作用 [英] Mail function is not working in PHP

查看:128
本文介绍了邮件功能在PHP中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php 

if(isset($ _ POST ['submit']))
{
//如果电子邮件已填写,继续

$ name = mysql_real_escape_string($ _ POST ['name']);
$ phone = mysql_real_escape_string($ _ POST ['phone']);

$ to =admin@gmail.com;
$ subject =顾客注意;
$ message =买家信息并在土地上投资。
$ message。=客户名称:$ name。\\\
;
$ message。=客户电话:$电话。\\\
;

$ mail = mail($ to,Subject:$ subject,$ message);
if($ mail){
echosuccess;
} else {
echofailed。;
}
?>

我使用上面的代码发送电子邮件但是我无法得到结果..它总是显示谢谢信息..



我可以获取名称和电话的价值。



如何解决这个问题?

解决方案

  mail($ to, :$ subject,$ message); 
echo谢谢你使用我们的邮件表单;

而不是这样,首先检查邮件是否发送

  $ mail = mail($ to,Subject:$ subject,$ message); 
if($ mail){
echo谢谢你使用我们的邮件表单;
} else {
echo邮件发送失败;
}

实际上你可以知道你的邮件功能是否正常工作, p>

如果它不工作。问题可以通过SMTP设置在您的本地主机



启用php中的错误如果不是启用使用

  ini_set('display_errors',1); 


<?php

if (isset($_POST['submit']))
  {
 //if "email" is filled out, proceed

$name=  mysql_real_escape_string($_POST['name']);
$phone=  mysql_real_escape_string($_POST['phone']);

 $to = "admin@gmail.com";
$subject = "Customer Intrested";
$message = "Buyer Information and Intrested in land.";
$message.= "Customer Name :".$name."\n";
$message.= "Customer Phone :".$phone."\n";  

$mail=mail($to, "Subject: $subject",$message );
if($mail){
 echo "success";
  }else{
 echo "failed."; 
  }
?>

I am using the above code to send email..but i am unable to get the result..it always showing the "Thank you message"..

I can able to get the values of name and phone.

How to fix this Problem?

解决方案

mail($to, "Subject: $subject",$message );
echo "Thank you for using our mail form";

instead of this ,first check if the mail is sent

$mail=mail($to, "Subject: $subject",$message );
if($mail){
  echo "Thank you for using our mail form";
}else{
  echo "Mail sending failed."; 
}

By this actually u can know whether your mail function in working or not

if it is not working.the problem can be with SMTP settings in your localhost

enable errors in php if not enabled using

ini_set('display_errors',1);

这篇关于邮件功能在PHP中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆