簡體   English   中英

表單數據已發布但未通過php mail()發送

[英]Form data being posted but not being sent with php mail()

我正在創建一個工作申請表,該表具有一個下拉框,用戶可以從中選擇一個城市並繼續填寫該表。 這里的目標取決於用戶選擇的城市,然后提交表格,表格將被發送到分配該選項值的電子郵件地址。 我已經能夠成功地在“名稱,電子郵件和消息”之類的簡單表單字段上完成這項工作。 但是,由於我實際上已經開始創建表單和更多表單字段,因此它不再起作用。 我進行了一些測試,其中一個使用print_r($_POST); 提交表單后,它將顯示已發送的所有表單值,但不會使用mail()函數將這些結果mail()出去。 php代碼如下:

    <?php


//Sanatize field inputs

if(isset($_POST['post'])) {
    // check reCAPTCHA information
        require_once('recaptchalib.php');

        $privatekey = "6LcuhsgSAAAAAJ1Xlct4dmqOT2SnlhOuwAEImAXH ";
        $resp = recaptcha_check_answer ($privatekey,
        $_SERVER["REMOTE_ADDR"],
        $_POST["recaptcha_challenge_field"],
        $_POST["recaptcha_response_field"]);
 // if CAPTCHA is correctly entered!                       
if ($resp->is_valid) {
            $headers = "From: $email\r\n";
            $headers = "Reply-To: $email\r\n";
            $headers = "MIME-Version: 1.0\r\n";
        $headers = "subject: Application\r\n";
            $headers = "Content-Type: text/html; charset=utf-8\r\n";
        $cities = $_POST['cities'];               
        $lastname    = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING); 
        $firstname  = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
        $middle = filter_var($_POST['middle'], FILTER_SANITIZE_STRING);
        $street = filter_var($_POST['street'], FILTER_SANITIZE_STRING);
        $city   = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
        $state  = filter_var($_POST['state'], FILTER_SANITIZE_STRING);
        $zip    = filter_var($_POST['zip'], FILTER_SANITIZE_STRING);
        $email   = filter_var($_POST['email'], FILTER_SANITIZE_STRING); 
        $hphone = filter_var($_POST['hphone'], FILTER_SANITIZE_STRING);
        $cphone = filter_var($_POST['cphone'], FILTER_SANITIZE_STRING);
        $social = filter_var($_POST['social'], FILTER_SANITIZE_STRING);
        $referral   = filter_var($_POST['referral'], FILTER_SANITIZE_STRING);
        $position   = filter_var($_POST['position'], FILTER_SANITIZE_STRING);
        $pay    = filter_var($_POST['pay'], FILTER_SANITIZE_STRING);        

        $message = "
        New mail from:<br><br>
        Name: $firstname&nbsp;$lastname <br>
        Email: $email <br>
        Message: $position <br >
        $pay";
        //$to   = "testing@website.com";
            //Here I provide the email address for cities
        $email1 = "testin1g@website.com";
        $email2 = "testing2@website.com";
        $email3 = "testing3@website.com";
        //print_r($_POST);
            // Logic for getting the value of drop down and then sending mail.
        if ($cities == "NY"){
            $sendMail = mail($email1, $message, $headers);
                if($sendMail) {
                    echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
                } else {
                     echo 'An error occured and the mail could not be sent.<br>
                    Please try again later.';
                }
        }
        elseif ($cities == "NC"){
            $sendMail = mail($email2, $message, $headers);
                if($sendMail) {
                    echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
                } else {
                     echo 'An error occured and the mail could not be sent.<br>
                    Please try again later.';
                }
        } elseif ($cities == "TX"){
            $sendMail = mail($email3, $message, $headers);
            if($sendMail) {
                    echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
                } else {
                     echo 'An error occured and the mail could not be sent.<br>
                    Please try again later.';
            }
        } elseif ($cities == "ME"){
            $sendMail = mail($email1, $message, $headers);
            if($sendMail) {
                    echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
                } else {
                     echo 'An error occured and the mail could not be sent.<br>
                    Please try again later.';
            }
        }    
    } else {
        // handle the CAPTCHA being entered incorrectly
        echo 'You Did not enter the CAPTCHA in correctly. Please go back and do so.';
    }
}
session_destroy();  
?>

如您在上面看到的,我列出了幾個電子郵件地址,然后使用if語句告訴php是否將“ city = state”發送到該電子郵件地址。 但是,這是它掛斷的部分。 它直接轉到我的錯誤消息。

和我的HTML形式:

<form method="post" action="../sendemail.php">

      <table cellpadding="0" cellspacing="0" width="900">
        <tr>

          <td width="800" bgcolor="White">

            <div id="copyContainerwide">
<h1>NexxLinx Career Opportunities</h1>
              <p>
               Thank you for your interest in a career with NexxLinx! We have many different opportunities for employment, which may vary depending 
               upon which center you are interested in applying for. For more information on what positions we have available, please contact your local
               NexxLinx centers, or visit us in person! </p>

 <br/>
 <p>To apply please select the center you would like to apply to:</p>

<select name="cities">
<option value="NY">Newburgh, NY</option>
<option value="NC">Jacksonville, NC</option>
<option value="TX" >Austin, TX</option>
<option value="ME">Orono, ME</option>
<option value="UT">South Jordan, UT</option>
</select>
<br/>
<p> TO THE APPLICANT: You must fully complete this application for it to be considered. Applications are active for ninety (90) days; 
              thereafter, you must personally renew the application to be considered for employment. We provide equal opportunities to all applicants 
              and employees without regard to race, color, religion, sex, national origin, age, or disability, in accordance with applicable federal 
              and state laws. Accommodation is available to applicants with a disabling condition, when applying, testing, or interviewing for a position.
              Please contact the Human Resource Department to request accommodation.</p>

 <fieldset>
 <legend>General Information </legend>
 <table>
    <tr>
        <td>Last Name:<br/>
            <input name="lastname" type="text" size="30" /></td>
        <td> First Name:<br/>
            <input name="firstname" type="text" size="30"/></td>
        <td> Middle Name:<br/>
             <input name="middle" type="text" size="30"/></td>
    </tr>
    </table>
    <table>
    <tr>
        <td>Street Address<br/>
        <input name="street" type="text" size="50" /></td>
        <td> City<br/>
        <input name="city" type="text" size="30" /></td>
        <td>State (abbr.)<br/>
         <input name="state" type="text" size="7"  /></td>
        <td> Zip Code <br/>
        <input name="zip" type="text" size="12"  /></td>
     </tr>
     </table>
     <table>
     <tr>
        <td>E-mail:<br/>
        <input name="email" type="email" size="50" /></td>
        <td>Home Phone:<br/>
        <input name="hphone" type="tel" size="15" /></td>
        <td>Cell Phone:<br/>
        <input name="cphone" type="tel" size="15" /></td>
        <td>Social Security Number<br/>
        <input name="social" type="text" size="12" /></td>
      </tr>
      </table>
      <table>
      <tr>
        <td>Referred By:</td>
        <td><input name="agency" type="checkbox" />Agency</td>
        <td><input name="advert" type="checkbox" />Advertisement</td>
        <td><input name="employee" type="checkbox" />Empoloyee</td>
        <td><input name="other" type="checkbox" />Other</td>
      </tr>
      <table>
      <tr>
        <td>Please list the name of the above agency, publication with the advertisement, employee, or other referall.<br/>
        <input name="referral" type="text" size="60" /></td>
       </tr>
       </table>
       <table>
        <tr>
        <td>Position Applied For:<br/>
        <input name="position" type="text" size="50"/></td>
        <td>Pay Desired:<br/>
        &#36;<input name="pay" type="text" size="20" /></td> 
        </tr>
        <tr>
        <td>
        <?php
    require_once('../recaptchalib.php');
    $publickey = "6LcuhsgSAAAAAHtXF5i5f5XEAZmjyAtYvHGGQlhf ";
    echo recaptcha_get_html($publickey);
?>
        </td>
        </tr>
        <tr>
        <td>
        <input type="submit" name="post" value="submit" />
</table>
 </fieldset>
 </div>
 </td>
 </tr>
 </table>
 </form>

感謝您給我的任何建議!

更新:終於可以工作了! 謝謝大家的幫助。 無論出於何種原因,如果這不正確,請更正,我將標頭移至所有其他變量的頂部,現在它就像一個符咒。 僅供參考:我正在WAMP上進行本地處理,並配置了杜比sendmail通過我的gmail帳戶發送。 它使用非常簡單的形式工作,但是顯然這有點太高級了,所以我最終上傳並完成了在實時服務器上的測試。

也許有人可以幫助我的其他事情是驗證社會保險號,並在有人輸入數字時顯示*。 可以用javascript完成嗎?

為什么不將電子郵件地址分配給該區域的值,如果您想將其插入數據庫中時總是可以反轉的話

<select name="cities">
<option value="test1@yahoo.com">Newburgh, NY</option>
<option value="test2@yahoo.com">Jacksonville, NC</option>
<option value="test3@yahoo.com" >Austin, TX</option>
</select>

$to=$_POST['cities'];

mail('$to', '$subject', '$message);

如果您需要在數據庫中插入位置,只需將其反轉即可

    if($citiies==test1@yahoo.com)
{
//insert into database NY
}

該代碼較短,看起來更干凈,但是如果要將位置存儲在數據庫中,則需要再次編寫該代碼

它會更短,因為您不會比較值,而只是將其發送到指定的值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM