dongxianchu3541 2014-04-26 21:46
浏览 17
已采纳

PHP联系表单返回成功,但不发送任何内容[重复]

This question already has an answer here:

I'm working on a personal portfolio website (www.corybolles.com) and I'm attempting to create a contact from based off of PHP. I have very little knowledge of PHP compared to HTML and CSS, and I was wondering if anyone could help me figure out why this is not working correctly.

HTML

<div id="contact">
            <form action="contact.php" method="post">
                <label>Name</label><br>
                <input class="forminput" type="text" name="cf_name" width="50px"><br>
                <label>Email</label><br>
                <input class="forminput" type="text" name="cf_email" width="50px"><br>
                <label>Message</label><br>
                <textarea class="forminput" name="cf_message" cols="18" rows="10"></textarea><br>
                <input class="formbutton" type="submit" name="submit"value="Send">
                <input class="formbutton" type="reset"  name="clear" value="Clear">
            </form>
        </div>

PHP

<?php

$name = $_POST['cf_name'];
$email = $_POST['cf_email'];
$message = $_POST['cf_message'];
$from = 'From: www.corybolles.com'; 
$to = 'jcbollesjr@gmail.com';
$subject = 'Message from user via www.corybolles.com';

$body = "From: $name
 E-Mail: $email
 Message:
 $message";

?>

<?php

if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
    echo '<p>Thanks! Your message has been sent!</p>';
} else {
    echo '<p>Sorry, something appears to have broken. Please try again</p>';
    }
}   

?>

You can test it yourself, but whenever I fill out the form to test it, it returns a successful message, however doesn't actually send anything.

</div>
  • 写回答

3条回答 默认 最新

  • dream_life5200 2014-04-26 21:53
    关注

    Try this in a seperate file to check if mail is actually 'working', as your current code looks fine.

    <?php
    echo mail('your@address.com', 'your@address.com', 'test');
    ?>
    

    This script tries to send an email to your@address.com, from your@address.com, and echoes the return value of the function. If it doesn't echo 'TRUE' or '1', there is a weird problem. If it does, and you don't receive any mails in your mailbox, you should contact your server administrator.

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

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?