douwen7603 2013-11-30 07:19
浏览 20
已采纳

邮件功能在PHP中不起作用[重复]

This question already has an answer here:

<?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."
";
    $message.= "Customer Phone :".$phone."
";  

    $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?

</div>
  • 写回答

2条回答 默认 最新

  • dsbqfrr098575666 2013-11-30 07:28
    关注
    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?