【问题标题】:Need mail function inside index.php需要 index.php 中的邮件功能
【发布时间】:2020-02-11 06:48:50
【问题描述】:

需要将 mail() 添加到我尝试过的 index.php 中,但它不起作用。 我已经尝试了几种不同的方法并阅读了 php 网页,我知道为什么它不起作用

<div class="card p-3">
<form action="insert.php" method="post" enctype="multipart/form-data">
  <div class="form-group text-center">
    <h3 style="color:#5892c5;">Schedule Your Free Quote</h3>
  </div>
  <div class="form-group">
    <label for="exampleInputName">Name<span class="required"style="color:red;"> *</span></label>
    <input type="text" name="customer" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter First + Last Name">
  </div>
  <div class="form-group">
    <label for="exampleInputPhone">Phone Number<span class="required"style="color:red;"> *</span></label>
    <input type="phone" name="phone" class="form-control" id="exampleInputPhone" aria-describedby="phoneHelp" placeholder="Enter Mobile Phone">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
  </div>
  <div class="form-group">
    <label for="exampleInputConcerns">Any Concerns?</label>
    <textarea class="form-control rounded-0" name="concerns" id="exampleFormControlTextarea2" rows="3" placeholder="Message"></textarea>
  </div>

  <button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php

  $message = $_POST['name'] . $_POST['phone'] . $_POST['email'] . $_POST['concerns'];

  $email_subject = "New Form submission";

  $email_body = "You have received a new message from the user \n".
                            "Here is the message:\n $message".

  $to = "my_email@email.com";


  mail($to,$email_subject,$email_body);
?>
</div>

【问题讨论】:

标签: php


【解决方案1】:

尝试使用 PHPMailer。很容易实现,只需下载包并按照此页面上的说明进行操作即可:https://github.com/PHPMailer/PHPMailer

【讨论】:

    【解决方案2】:

    您可以使用 PHP mail() 函数如下:

    <?php
        $to = "emailName@email.com";
        $subject = "New Lead";
        $message = "'$customer' '$phone' '$email' '$concerns'";
        
        mail($to,$subject,$message);
    ?>
    

    注意:您应该指定发送邮件的电子邮件地址。您可以在php.ini 文件中指定它。如果您仍然感到困惑,您可能想访问:https://www.w3schools.com/php/func_mail_mail.asp 以了解有关此功能的更多信息。

    【讨论】:

    • 我会在 php.ini 中添加什么?我不得不创建文件,因为没有。我将该功能添加到我的索引页面,但我仍然没有收到电子邮件。
    • @Nick Du Plessis,/etc/php/7.4/apache2/ 目录中应该有一个名为php.ini 的文件。在那里您可以更改它(请注意,由于您使用的 PHP 版本,目录的路径可能会有所不同)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多