To和From在php中返回相同的电子邮件ID

时间:2014-04-15 11:37:05

标签: php html email pear

这是我的PHP代码:

<?php
        require_once "Mail.php";

        $name=trim($_POST['name']);
        $email=trim($_POST['email']);
        $phone=trim($_POST['phone']);
        $message=trim($_POST['message']);

                $from = $email;
                $to = "fyproject.com@gmail.com";    //$_SESSION['mto'];//
                $subject = "You have a message from '$name'";
                $body = $message;

                $host = "ssl://smtp.gmail.com"; //"smtp.gmail.com";
                $port = "465";//"587";
                $username = "fyproject.com@gmail.com";
                $password = "************";
                $headers = array ('From' => $from,
                      'To' => $to,
                      'Subject' => $subject);

                $smtp =@ Mail::factory('smtp',
                      array ('host' => $host,
                        'port' => $port,
                        'auth' => true,
                        'username' => $username,
                        'password' => $password));

                $mail = @$smtp->send($to, $headers, $body);
                    echo "Trying to send email ....";

                if (@PEAR::isError($mail)) {
                      echo("<p>" . $mail->getMessage() . "</p>");
                } else {
                      echo("<p>Message successfully sent!</p>");
                }
    ?>

我的HTML表单是这样的:

<form action="includes/contact.php" method="post" id="ContactForm">     
                                        <fieldset class="left"> 
                                                    <div class="block">
                                                    <label class="name padRight3">
                                                        <span class="title1">Name:</span>
                                                        <span class="bg"><input type="text" name="name" pattern="[A-Za-z]{3,20}\s[A-Za-z]{3,20}$" title="Type your name and surname. Special Characters not allowed" class="input" required autofocus></span>
                                                        </label>
                                                     <label class="email">
                                                        <span class="title1">Email:</span>
                                                        <span class="bg"><input type="email" name="email" class="input" required></span>
                                                        </label>   

                                                     <label class="phone">
                                                     <span class="title1">Phone:</span>
                                                        <span class="bg"><input type="tel" name="phone" pattern="\d{10}" class="input"></span>
                                                        </label>
                                                     </div>

                                                     <div class="block">
                                                     <label class="message">
                                                     <span class="title1">Message:</span>
                                                        <span class="bg"><textarea rows="1" cols="2" name="message" required></textarea></span>
                                                        </label>
                                                     </div>
                                                     <div class="formButtons">
                                                      <div class="formBtn">
                                                            <input type="submit" value="send" />
                                                      </div>
                                                      <div class="formBtn">
                                                            <input type="reset" value="clear" />
                                                      </div>
                                                     </div> 
                                            </fieldset>
                                        </form>

我为联系我页面创建了此代码。现在,当用户提交具有字段名称,电子邮件,电话和消息的联系表单时,我会收到电子邮件,其中from和to都是我的电子邮件ID。虽然我在表单中提供了属性name ='email'和method ='post'。它没有检索用户的电子邮件,而是显示我提供的用于接收邮件的电子邮件。但其他领域的工作正常。我不明白我哪里出错了。任何帮助赞赏。谢谢

0 个答案:

没有答案