繁体   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