没有从PHP代码接收电子邮件

时间:2013-09-27 17:30:38

标签: php

没有收到电子邮件。这是推动我NUTS,原来的问题, 之前只是在田野里。电子邮件,主题,消息。我得到了 电子邮件,但我无法看到电子邮件变量。刚刚进来, 从我的服务器。所以我无法回复收到的任何电子邮件。想到了 添加另一个字段。 “再次发电子邮件”,但它说它正在发送电子邮件, 我的收件箱里什么也没收到。这是什么问题? (注意: 电子邮件出于安全原因而被淘汰出局)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>testing</title>
<style type="text/css">
body,td,th {
    color: #F7F3F3;
}
body {
    background-color: #050505;
}
</style>
</head>
<body style="text-align: center">
<?php ?>
<br />
<?php 
if (isset($_POST['submit'])){
{
    //excute the code
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $eg = $_POST['eg'];
    $message = $_POST['message'];

    if (strlen($email) <= 0)
        {
        echo "You need to enter an email";
    }else{
        if (strlen($subject) <= 0)
            {echo "You need to enter a subject";
        }else{
                        if (strlen($message) <= 0)
                    {echo "You need to enter a message";
            }else{
                            if (strlen($eg) <= 0)
                        {echo "Email Again";
                }else{
                    if(filter_var($email, FILTER_VALIDATE_EMAIL) == true){
                    //continue with code
                    mail("random@gmail.com", $subject, $message, $eg,  "From:$email");
                    echo "Your message has been sent";
                    }
                        else
                            {
                        echo "You must fill out the entire form";
                            }
                     }
                }
            }
}
}
}
?>
<br />
<span style="text-align: center">This is the contact form.</span>
<form method="post" action="testing.php">
  <table align="center" style="color: #030303;">
<tr><td>Email: <input type="text" name="email" /></td></tr>
<trd><td>Email Again:<input type="text" name="eg" /></td></tr>
<trd><td>Subject:<input type="text" name="subject" /></td></tr>
<trd><td><label for="textarea">Message:</label>
<textarea name="message" cols="40" rows="15">Type your message here.</textarea></tr><tr>
  <trd><td><input type="submit" name="submit" value="send" /></td></tr>
</table>
</form>

2 个答案:

答案 0 :(得分:0)

更正您的<tr>代码,可能会导致问题

<trd><td>Email Again:<input type="text" name="eg" /></td></tr>
   ^
<trd><td>Subject:<input type="text" name="subject" /></td></tr>
   ^
<trd><td><label for="textarea">Message:</label>
   ^
<textarea name="message" cols="40" rows="15">Type your message here.</textarea></tr><tr>
  <trd><td><input type="submit" name="submit" value="send" /></td></tr>
     ^

正确的方法是

<tr><td>Email Again:<input type="text" name="eg" /></td></tr>
<tr><td>Subject:<input type="text" name="subject" /></td></tr>
<tr><td><label for="textarea">Message:</label>
<textarea name="message" cols="40" rows="15">Type your message here.</textarea></tr><tr>
  <tr><td><input type="submit" name="submit" value="send" /></td></tr>

答案 1 :(得分:0)

您将邮件字段$_POST['eg']作为邮件标头传递。这将不可避免地导致某种问题。

mail("random@gmail.com", $subject, $message, $eg,  "From:$email");

应该是

mail("random@gmail.com", $subject, $message, "From:$email");

删除$eg参数。第四个位置是标题字符串。第五个可以是附加参数,但我想你可能想看一下这实际意味着什么。请参阅此处的文档:

http://php.net/manual/en/function.mail.php

更新

$header = "Reply-To: username@webhosting400.myserver.net\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/plain; charset=utf-8\r\n"; 
$header.= "X-Priority: 1\r\n"; 

mail("random@gmail.com", $subject, $message, $header);