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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀