0

I am building a website for a school project(freshman) and wish to add a simple feedback form to it, which send emails to my personal gmail account. I don't really get an error but it doesn't send anything. The website uses Laravel but the feedback form I'm building is in simple php (it's mandatory for me to use some plain php). I have disabled that security setting in my google email, so that's not the issue. I already have a working Forgot Password function built with laravel which can send mails, but I don't know why this mail() function in plain php is not working.

Operating system is Ubuntu

Code:

<?php
    if ( isset( $_GET['submit2'] ) ){

   $to = "redacted@gmail.com";
   $subject = "Feedback for the Website!";
   $body = "A user has entered feedback on the site!\n";
   $body .= "Their feedback is:\n\n";
   $body .= $feedback ?? '';
   print "Thanks for your feedback!";
   mail($to, $subject, $body);
    }
   else {
   ?>
  <form action="feedback" method="GET">
  <h2>1Please Send us your Feedback</h2>
  <textarea cols=35 rows=15 name="feedback">
  </textarea>
  <br>
  <input type="submit" name="submit2" value="Submit">
  </form>
 <?php

php.ini

[mail function]
; For Win32 only.
; http://php.net/smtp
XAMPP
SMTP=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587

; For Win32 only.
; http://php.net/sendmail-from


; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
http://php.net/sendmail-path
;sendmail_path=/opt/lampp/lib/php/Mail/sendmail.php
sendmail_from=redacted@gmail.com
auth_username=redacted@gmail.com
auth_password=redactedPassword
  • You aren't setting a from address or any other headers. Study some simple examples of the use of mail(), there are plenty of tutorials available. Or use PHPMailer instead, it's easier to get it right – ADyson Jun 28 '21 at 18:00
  • I did follow a guide and it said (or i missunderstood) that i must specify it in php.ini and maybe you missed that but i did specify it there. – rrexha.Tirana Jun 28 '21 at 18:05
  • Ah yes. Some basic headers will still be beneficial, though. – ADyson Jun 28 '21 at 18:19
  • 1
    And this is required reading in general about email problems. Unfortunately there are _a lot_ of obscure things that can go wrong. [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – ADyson Jun 28 '21 at 18:19

1 Answers1

1

Ok so apparently it's because gmail was my recipent and it would filter my email out. I used a 10 minute temp email with literally 0 security and the code actually works(not sure how useful it is in real life scenarios though).