0

i have downloaded a contact script(with file attachment) from net.i am running it in wamp(pc) but when i click submit it shows this error.can you help me with this error

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\contact.php on line 38 Call S

and can you please tell me that whether the below script will work or not if not can you suggest a good contact form with file attachment

  <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>');
   }
  ?>
4

3 に答える 3

1

Dan Grossman が述べたように、あなたのコードは問題なく、発生しているエラーは SMTP 設定です。これらの設定を修正し、localhost をセットアップして gmail (またはその他の外部 SMTP サーバー) を使用して電子メールを送信する方法を説明します。

まず、php.ini ファイルを見つけて、sendmail_path を次のように設定する必要があります。

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

sendmail.iniWAMP インストールの「Sendmail」フォルダーを見つけて、以下を追加します。

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

サーバーを再起動します。これで、メールを送信できるはずです。

于 2011-07-27T05:39:42.920 に答える
1

コードに問題はなく、別のスクリプトに切り替えても役に立ちません。

問題は、メールの送信に使用するメール サーバーがコンピューター上で実行されていないことです。

于 2011-07-27T05:17:59.640 に答える
-1

あなたの問題は、フォームの送信ではなく、メール機能にあります。

php.ini の変更に関するヘルプを取得する

于 2011-07-27T05:18:22.760 に答える