-2

我对这一切都很陌生,需要帮助......我有一个我想发送的论坛,但由于某种原因它没有发送。mailto 函数不会在服务器上发送电子邮件,也不会刷新到 redirect.html。这是我的代码:

 <?php 
                $problem = FALSE;
                if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                    if (empty($_POST['name'])) {
                        $problem = TRUE;
                        print '<p class="important">&bull;&nbsp;What is your name?</p>';
                    }   
                    if (empty($_POST['email'])) {
                        $problem =TRUE;
                        print '<p class="important">&bull;&nbsp;What is your email?</p>';
                    }
                    if (empty($_POST['message'])) {
                        $problem =TRUE;
                        print '<p class="important">&bull;&nbsp;What is your message?</p>';
                    }
                    if ($problem = TRUE) {print '<br />';}
                    }
            ?>
            <form action="index.php" id="contact_me" method="post">
            <table border="0" cellspacing="0" cellpadding="0" width="500">
                  <tr>
                    <td width="160">Your Name:<span class="important">*</span></td>
                    <td width="340"><input name="name" type="text" size="30" value="<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['name'])) { print htmlspecialchars($_POST['name']); }}?>"/>
                    </td>
                  </tr>
                  <tr>
                    <td><p>Your Email:<span class="important">*</span></p>
                    </td>
                    <td><input name="email" type="text" size="30" placeholder="example@example.com" value="<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['email'])) { print htmlspecialchars($_POST['email']); }}?>"/></td>
                  </tr>
                  <tr>
                    <td>Message:<span class="important">*</span></td>
                    <td><textarea name="message" rows="6" cols="40" placeholder="Your message here"><?php if($_SERVER['REQUEST_METHOD']=='POST'){if(isset($_POST['message'])){print htmlspecialchars($_POST['message']);}}?></textarea></td>
              </tr>
            </table><br />
            <input type="submit" name="submit" id="submit" value="Submit" >
            </form>
            <?php
            // Start the email function
            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                    if ($problem == FALSE) { // holy cow they didn't mess up
                        $name=$_REQUEST['name']; 
                        $email=$_REQUEST['email']; 
                        $message=$_REQUEST['message'];   

                        $from="From: $name<$email>\r\nReturn-path: $email"; 
                        $subject="Mathew Blair - Contact form"; 
                        mail("mathewblair@live.com", $subject, $message, $from);

                        Header("Location: redirect.html");
                    }
            }
            ?>

谢谢您的帮助!

4

3 回答 3

2

在你最后的情况下

 if ($problem = TRUE) {print '<br />';}

你没有检查是否problemtrue但你正在problem设置TRUE

将其更改为:

 if ($problem == TRUE) {print '<br />';}
于 2013-07-21T19:27:02.433 回答
0

您所在的服务器需要安装邮件服务,例如 sendmail 或 postfix。

在 Ubuntu 上,这是

sudo apt-get install sendmail

或者

sudo apt-get install postfix

您可能需要更改 php.ini ( http://php.net/manual/en/mail.configuration.php ) 中的邮件配置。

另外,对于发送电子邮件,我发现最好使用完整的类而不是仅使用邮件功能。这样的类将使与 3rd 方邮件网关(例如 gmail)的连接变得更加容易。因此,您将能够通过 gmail 的 SMTP 服务器从您的 Web 应用程序发送电子邮件,这对于不将您发送的电子邮件检测为垃圾邮件要好得多。这里有三个很好的包。我推荐 swiftmailer。

http://swiftmailer.org/

https://github.com/Synchro/PHPMailer

http://framework.zend.com/manual/1.12/en/zend.mail.html

http://pear.php.net/package/Mail_Mime

于 2013-07-21T19:27:21.253 回答
0

您需要配置 SMTP 才能mail正常工作。

mail由于配置错误,该功能也可能出现故障。您将不得不编辑您的 php.ini 文件。

于 2013-07-21T19:28:32.107 回答