So I just recently created my first Ec2 instance through AWS. I decided to go with the Ubuntu Server 18.04 LTS (HVM), SSD Volume Type. The first things I did when setting up the server was:
1. sudo apt-get update - updating the machine.
2. sudo apt-get -y upgrade - upgrade the machine to the newest software.
3. sudo apt-get -y install tasksel - installs software called tasksel
4. sudo tasksel install lamp-server - installs apache, php and mysql.
5. ln -s /var/www/html www - creates a www link in your home folder.
6. sudo chown -R ubuntu /var/www/html/ - take ownership of the html folder for easier access.
I then uploaded my html files to the html folder. I am able to access my website using my servers IP address however when I try to send an email it fails. Here is my PHP code:
<?php
$to = "email@gmail.com"; //<--------put email here
$subject = "subject";
$email = $_POST['email'];
$headers = "From: ".$email."\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "CC: \r\n";
$name = $_POST['realname'];
$number = $_POST['Phone'];
$comment = $_POST['Comments'];
$message = "Name: ".$name."\n"."Phone number: ".$number."\n"."Comment: ".$comment;
$didItSend = null;
if ($email == "Email" || $name == "Name" || $number == "Phone" || $comment == "Comments" || $email == "" || $name == "" || $number == "" || $comment == ""){
echo "<p>all fields must be filled with your information and the comment must be filled out!</p>";
} else {
$didItSend = mail($to, $subject, $message, $headers);
if ($didItSend === TRUE){
echo "<p>Email sent!</p>";
echo "<p> $to , $subject , $message , $headers</p>"; // all vars are correct
} else {
echo "<p>Failed to send Email. try entering a vaild email or try a different email account!</p>";
echo "<p> $to , $subject , $message , $headers</p>"; // all vars are correct
}
}
?>
at first $didItSend was false when I was trying to send an email then I did:
sudo apt-get install sendmail
and now when I try to send mail $didItSend is true, however the email never gets sent. Is there something I am missing here? What else do I have to do to get this to work? By the way my php code worked for another website I created that was on my schools server and it worked perfectly. So im thinking that I didn't set something up correctly.