简体   繁体   English

为什么 PHP mail() 函数不发送邮件?

[英]Why does PHP mail() function not sending mail?

I have been trying to make this script where the user info from a form will be sent over to someone by mail and also the same information will save that exact information in a .txt file.我一直在尝试制作此脚本,其中表单中的用户信息将通过邮件发送给某人,并且相同的信息会将确切信息保存在 .txt 文件中。

if (isset($_POST['enquire'])) {

    //set variables
    $name = $_POST['name'];
    $mobile = $_POST['phone'];
    $email = $_POST['email'];   
    $cust_message = $_POST['message'];


//set mail vairables
    $to = "someone@example.com";
    $subject = "Enquiry on ABC";

//message   
    $message = ' //proper HTML is used removed here to make this code shorter
        <h1>New Enquiry on ABC!</h1> 
        <table cellspacing="0" style="border: 1px solid whitesmoke; max-width: 500px;width:50%;"> 
            <tr> <th>Name:</th><td>'.$name.'</td> </tr> 
            <tr> <th>Email:</th><td>'.$email.'</td> </tr> 
            <tr> <th>Mobile:</th><td>'.$mobile.'</td> </tr> 
            <tr> <th>Message:</th><td>'.$cust_message.'</td> </tr>
        </table>';

//set headers   
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
    $headers .= "From: enquiry@example.com" . "\r\n". "CC: someone_else@example.com";

//shoot the mail
    mail($to,$subject,$message,$headers);

// write to file
    $myfile = fopen("leads.txt", "a+") or die("Unable to open file!");
    $txt = "Name: ".$_POST['name']."\r\n"."Email: ".$_POST['email']."\r\n"."Number: ".$_POST['phone']."\r\n";
    fwrite($myfile, $txt);
    fclose($myfile);

}

One weird thing is I am not receiving any email and nither I am seeing any error Log!一件奇怪的事情是我没有收到任何电子邮件,也没有看到任何错误日志!

It was a Buggy HTML form.这是一个错误的 HTML 表单。

So in the HTML has a submit button which did not have any name="" attribute.所以在 HTML 中有一个没有任何 name="" 属性的提交按钮。 Hence isset() was not true and the script didn't work.因此 isset() 不正确并且脚本不起作用。

Thank you all for the taking time to answer it.感谢大家抽出时间来回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM