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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题