【问题标题】:Send form details to email将表格详细信息发送到电子邮件
【发布时间】:2017-10-28 01:25:26
【问题描述】:

我创建了一个表单和 php 以将表单详细信息发送到我的电子邮件。但是,当通过 localhost 通过 wampserver 运行网页时,它会显示错误为“警告:邮件():无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用C:\wamp\www\My original web\PHP\ContactUs.php 中的 ini_set() 第 22 行"。我找不到第 22 行的错误。

<div class="container">
  <form name="htmlform" method="POST" action="../PHP/ContactUs.php">
  
    <label for="name">Name</label>
    <input type="text" id="name" name="name" placeholder="Your Name">

    <label for="email">Email Address</label>
    <input type="text" id="email" name="email" placeholder="Your Email Address">

     <label for="phone">Phone Number</label>
    <input type="text" id="phone" name="phone" placeholder="Your Phone Number">

    <label for="Message">Message</label>
    <textarea id="message" name="message" placeholder="Write You Something" style="height:200px"></textarea>

    <input type="submit" value="Submit">
  </form>
  
  <?php
//if "email" variable is filled out, send email
  if (isset($_REQUEST['email']))  {
  
  //Email information
  $admin_email = "pinkmaidbeautysalon@gmail.com";
   $name = $_REQUEST['name']; 
  $email = $_REQUEST['email'];
  $phone = $_REQUEST['phone'];
   $message = $_REQUEST['message'];
  
  //send email
  mail($admin_email, "$name", "$phone", "$message", "From:" . $email);
  
  //Email response
  echo "Thank you for contacting us!";
  }
  
  //if "email" variable is not filled out, display the form
  else  {
?>

 
  
<?php
  }
?>

【问题讨论】:

  • 与其使用$_REQUEST(可以同时使用$_POST 和$_GET 方法),不如使用$_POST。该错误表明您正在开发系统上尝试此操作并且没有运行邮件服务器
  • @RamRaider 如何设置邮件服务器?
  • 这是一个相当广泛的主题,当 php 脚本将托管在反正以后上网?我会在 php 代码中添加一些逻辑,以检查您是否在 localhost 上运行,如果是,则不发送电子邮件。或者,尝试搜索"free mail server for windows" 或查看stackoverflow.com/questions/16830673/… ~ 那里有很多解决方案
  • @RamRaider 不使用邮件服务器,是否无法将详细信息发送到电子邮件?
  • 是的 - 你需要一个邮件服务器来发送电子邮件

标签: php html css email


【解决方案1】:

对您来说最好的选择是使用PHPmailer,这将使您能够正确发送邮件并节省大量时间。
How To Use PHPMailer 本教程将为您提供指导。

【讨论】:

    【解决方案2】:

    您应该使用标题。并且您可以使用任何第三方服务器测试工具来测试本地主机中的邮件。例如:-“测试邮件服务器工具”

        <?php
    
        $admin_email = "pinkmaidbeautysalon@gmail.com";
        $name = $_REQUEST['name']; 
        $email = $_REQUEST['email'];
        $phone = $_REQUEST['phone'];
        $message = $_REQUEST['message'];
            if(!empty($email))
            {
                $headers = 'From:'.'pinkmaidbeautysalon@gmail.com' . "\r\n" .
                    'Reply-To: Pink maid beauty saloon <pinkmaidbeautysalon@gmail.com>' . "\r\n" .
                    'X-Mailer: PHP/' . phpversion() . "\r\n" .
                    'Content-type: text/html; charset=iso-8859-1';
    
                //mail (from,subject,body,headers)
                mail($admin_email,"Your saloon", "$name "."$phone "."$message", $headers);
                echo "Email successfully sent";
    
    
            }
            mysqli_close($con);
    
        ?>
    

    【讨论】:

      猜你喜欢
      • 2018-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多