duancanjiu3754 2014-04-04 12:27
浏览 280
已采纳

无法将我的表单数据发送到我的电子邮件

I'm trying to get all the data entered into the form on my website sent to my email when submitted, but just can't seem to get it to work...

This is my email.php file..

<?php

$EmailFrom = "dcmagpies@hotmail.co.uk";
$EmailTo = "  dcmagpies@hotmail.co.uk";
$Subject = "online form message";
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['feedback']));
// validation
$validationOK=true;
if (!$validationOK) {
echo "please check your details";
header("");
exit;
}

// prepare email body text

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "Thankyou"

}
?>

My html code...

<form name="contactform" method="post" action="emailphp.php">
    <table width="450px">
<tr>
    <td valign="top">
    <label for="name">Name *</label>
</td>
    <td valign="top">
    <input  type="text" name="Name" maxlength="50" size="30">
</td>
</tr>
<tr>

    <td valign="top"">

    <label for="email">Email *</label>
</td>
    <td valign="top">
    <input  type="text" name="Email" maxlength="50" size="30">
</td>
</tr>

<tr>
    <td valign="top">
    <label for="feedback">Feedback *</label>
</td>
    <td valign="top">
    <input  type="text" name="Feedback" maxlength="150" size="30">
</td>
</tr>

<tr>
    <td colspan="2" style="text-align:center">
    <input type="submit" value="Submit">
</td>
</tr>
</table>
</form>

When i test it, after i enter some data in the form and submit it, it just shows the php code in the browser.

  • 写回答

2条回答 默认 最新

  • doulu1020 2014-04-04 12:42
    关注

    Make sure

    • check you saved php file in .php type
    • put echo $EmailTo.$Subject.$Body;die; if it shows values correct, you a problem in mail function line.
    • try like this "From: <".$EmailFrom.">" in mail function line.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题