简体   繁体   English

PHPMail 方法在带有 LAMPP 的 ubuntu 中不起作用

[英]PHPMail method not working in ubuntu with LAMPP

I created a contact form and it works correctly with phpmail method, but I'm facing one issue with not sent email.我创建了一个联系表单,它与 phpmail 方法一起正常工作,但我面临着一个未发送电子邮件的问题。 I'm getting one error based on below code using Ubuntu and LAMPP我使用 Ubuntu 和 LAMPP 根据以下代码收到一个错误

if (isset($_POST['sendmail'])){
     $person_name=$_POST['c_name']; 
     $email=$_POST['c_email'];
     $subject=$_POST['c_subject'];
     $message=$_POST['c_message'];

    $toEmail = "ourgmail@gmail.com";
    $mailHeaders = "From: " . $person_name . "<". $email .">\r\n";
    if(mail($toEmail,$subject,$message,$mailHeaders)) {  // checking sent or not
       echo "<script>alert('success')</script>";
    } else {
        echo "<script>alert('error')</script>"; //  email not sent and getting error here
    }
}

According to this comment at PHP mail() documentation :根据PHP mail() 文档中的此评论

Often it's helpful to find the exact error message that is triggered by the mail() function.通常,找到由 mail() 函数触发的确切错误消息会很有帮助。 While the function doesn't provide an error directly, you can use error_get_last() when mail() returns false.虽然该函数不直接提供错误,但您可以在 mail() 返回 false 时使用 error_get_last()。

 <?php $success = mail('example@example.com', 'My Subject', $message); if (!$success) { $errorMessage = error_get_last()['message']; } ?>

Also, keep in mind that to mail() work, your system must be properly configured to send emails.另外,请记住,要使 mail() 工作,您的系统必须正确配置以发送电子邮件。 Since setting up a mail server is not so simple (there's a lot of anti-spam restrictions), if you want to test it out, you can setup a SSMTP service on your system that uses a third party SMTP service like http://mailgun.com to sent it.由于设置邮件服务器不是那么简单(有很多反垃圾邮件限制),如果你想测试一下,你可以在你的系统上设置一个使用第三方 SMTP 服务的SSMTP服务,比如http:// mailgun.com发送它。 Check this question on Unix&Linux . 在 Unix&Linux 上检查这个问题

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

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