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条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来