douxing6532 2015-02-27 10:26
浏览 25
已采纳

PHP Mail不使用Ras Pi LAMP服务器在网站上发送

I run my bootstrap website on a Raspberry Pi LAMP server and I'm getting 'Error!' when sending a message using the contact form, the form uses two files using PHP Mail and the contact form is on the home page, here's the code:

Contact form on index.html:

<div class="col-sm-12">
<form class="form-horizontal" action="assets/php/contactForm.php" method="post" role="form" id="contactForm">
                        <div class="form-group">
                            <div class="col-sm-6">
                                <input type="text" name="name" class="form-control" placeholder="Name"> 
                            </div>
                            <div class="col-sm-6">
                                <input type="text" name="contactEmail" class="form-control" placeholder="Email">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <textarea name="message" class="form-control" rows="8" placeholder="Message"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-12">
                                <button type="submit" class="btn btn-theme ladda-button" data-style="expand-left">
                                <span class="ladda-label">Submit</span>
                                </button>
                            </div>
                        </div>
                    </form>

contactForm.php

<?php
include("include/settings.php");

if(isset($_POST['name']) && isset($_POST['contactEmail']) && isset($_POST['message'])){
$name = $_POST['name'];
$from = $_POST['contactEmail'];
$message = $_POST['message'];

$subject = "Message from " . $name;

if (mail ($to, $subject, $message, $from)) { 
    $response = array('sent' => 1);
    echo json_encode($response);
} else { 
    $response = array('sent' => 0);
    echo json_encode($response);
} 
}
?>

settings.php

<?php

// Contact
$to = 'xxxxxxx@hotmail.co.uk';
$subject = 'Contact Form from website';

?>

(email address removed and replaced by xxxxxxx just for this post for privacy reasons)

Any idea why i'm getting 'Error!' when using the form?

  • 写回答

2条回答 默认 最新

  • duanhai4046 2015-02-27 10:39
    关注

    From the command line on your Pi, can you test the following

    mail -s "Test Email" xxxxxxx@hotmail.co.uk < /dev/null
    

    to check the Pi is ready to send out mail. If not, you may need to install some sort of mail server (most guides point to postfix, but there are others). If you do want to install postfix, use the following

    sudo apt-get install postfix
    

    Also, in your /etc/php5/apache2/php.ini file, check what the sendmail_path option is set as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面