簡體   English   中英

帶有文件附件的php contact腳本中需要的幫助

[英]Help needed in php contact script with file attachment

我已經從net.net下載了一個聯系人腳本(帶有文件附件),我正在wamp(pc)中運行它,但是當我單擊“提交”時,它會顯示此錯誤。

警告:mail()[function.mail]:無法通過“ localhost”端口25連接到郵件服務器,無法驗證php.ini中的“ SMTP”和“ smtp_port”設置,或在C:\\ wamp \\ www \\中使用ini_set()第38行的contact.php致電S

能否請您告訴我以下腳本是否有效?如果不能,您可以建議一個帶有文件附件的好的聯系方式

  <form action="" enctype="multipart/form-data" method="post">

  <label for="name">Name:</label><br/>
   <input type="text" id="name" name="name" /><br/>

  <label for="email">Email address:</label><br/>
     <input type="text" id="email" name="email" /><br/>

    <label for="topic">Subject:</label><br/>
   <input type="text" id="topic" name="topic" /><br/>
   <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  <label>Upload a Menu:</label>
  <input type="file" name="file" size="20"><br>


  <label for="comments">Your comments:</label><br/>
  <textarea id="comments" name="comments" rows="5" cols="30"></textarea><br/>

   <button name="submit" type="submit">Send</button>

  </form>
  <?php
  if(isset($_POST['submit']))
   {
    // Pick up the form data and assign it to variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $topic = $_POST['topic'];
    $comments = $_POST['comments'];

    // Build the email (replace the address in the $to section with your own)
     $to = 'my@email.com';
     $subject = "Contact: $topic";
     $message = "$name said: $comments";
     $headers = "From: $email";

    // Send the mail using PHPs mail() function
   mail($to, $subject, $message, $headers);

  // Redirect
   echo('<br> your mail has been send<br>');
   }
  ?>

代碼沒有錯,切換到其他腳本無濟於事。

問題是您的計算機上沒有運行用於發送郵件的郵件服務器。

正如Dan Grossman提到的那樣,您的代碼很好,而您得到的錯誤是SMTP設置。 我將嘗試說明如何糾正這些設置,以及如何將localhost設置為使用gmail(或任何其他外部SMTP服務器)發送電子郵件。

首先,您需要找到php.ini文件並設置sendmail_path,類似於:

sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"

在WAMP安裝的“ Sendmail”文件夾中找到sendmail.ini ,並添加以下內容:

smtp_server=localhost
smtp_port=25
default_domain=gmail.com
auth_username=[yourgmailname]@gmail.com
auth_password=[yourgmailpassword]

重新啟動服務器。 現在它應該可以發送電子郵件了。

您的問題出在郵件功能上,而不是表單的提交上。

獲取有關更改php.ini的幫助

暫無
暫無

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

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