-3

I'm trying to build a php form but it keeps erroring out and i'm not sure why. Code

<?php

#Receive user input
$email_address = $_POST['email_address'];

#Send email
$headers = "From: $email_address";
$sent = mail('enscivwy@gmail.com', 'Feedback Form Submission', $email_address, $headers);

#Thank user or notify them of a problem
if ($sent) {
  echo "thanks!";
} else {
  echo "something went wrong";
}
?>

the error is "something went wrong"

ArSeN
  • 5,133
  • 3
  • 19
  • 26
Enscivwy
  • 89
  • 1
  • 8

1 Answers1

0

Do you have a mail server setup in your system?

If you already have a mail server, then kindly let me know.

If you do not have a mail server, you can install various mail servers like Postfix, Exim4 (more complicated, but more options for customization), etc.

My assumption is that you do not have a mail server.

To install postfix:

  • Ubuntu/Debian: sudo apt-get install postfix
  • CentOS/Fedora: First: sudo yum install epel-release, and sudo yum install postfix or sudo dnf install postfix
  • Arch Linux: sudo pacman -S postfix

DO NOT USE BOTH OF THEM TOGETHER, ELSE YOU WILL GET INTO MORE PROBLEMS!


To install exim4:

  • Ubuntu/Debian: sudo apt-get install exim4
  • CentOS/Fedora: First: sudo yum install epel-release, and sudo yum install exim or sudo dnf install exim
  • Arch Linux: sudo pacman -S exim

Side note:

You can use PHPMailer instead of the mail() function.

You have many features in PHPMailer like using DKIM, sending with attachments, and better error debugging.

Example person
  • 3,198
  • 3
  • 18
  • 45