-5

need to add mail() to my index.php I tried and it wont work. I have tried this a couple different ways and have read the php webpage, Idk why its not working

<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>
  • hi Nick, welcome to stackoverflow, have you checked the `mail()` documentation? they had examples on how to send mail and even [sending attachment](https://www.php.net/manual/en/function.mail.php#124702). – Bagus Tesa Feb 11 '20 at 07:06
  • 1
    Does this answer your question? [How to send an email using PHP?](https://stackoverflow.com/questions/5335273/how-to-send-an-email-using-php) – Bagus Tesa Feb 11 '20 at 07:07

2 Answers2

0

You can use PHP mail() function as following:

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

Note: you should specify the Email Address by which you want to send the message. You can specify it in php.ini file. If you're still confused, you may want to visit: https://www.w3schools.com/php/func_mail_mail.asp to know more about this function.

MBiabanpour
  • 370
  • 1
  • 13
  • what would I add to php.ini? I had to create the file since there was none. I add that function to my index page and I still did not receive an email. – Nick Du Plessis Feb 11 '20 at 07:44
  • @Nick Du Plessis, There should be a file called ```php.ini``` within the ```/etc/php/7.4/apache2/``` directory. There you can change it (notice that the directory's path might be different for you because of the version of PHP you're using). – MBiabanpour May 15 '21 at 19:48
0

Try using PHPMailer. It's easy to implement, just download the package and follow the instructions on this page: https://github.com/PHPMailer/PHPMailer

Ross
  • 66
  • 12