0

I currently have a php script to send emails from Ubuntu server with sendmail.

$to = $sendTo;
$subject = $subjectPrefix . $subject;
$txt = $message;
$headers = array(
  "From: ". $email,
  "Reply-To: ".$email,
  "Content-type:text/html;charset=UTF-8",
  "MIME-Version: 1.0",
  "X-Mailer: PHP/" . PHP_VERSION
);
$headers = implode("\r\n", $headers);

if(mail($to,$subject,$txt,$headers)){
  echo "sent";
}
else {
  echo "failed";
}

The emails send fine but always go into spam and have the server address attached to the email, for exmaple: "input@email.com"@ip-###-##-##-###.eu-west-2.compute.internal

How would i go about setting this to only show the input email and not go into spam?

Tristan
  • 15
  • 5
  • Observation: `implode` can be avoided if you restructure the array (PHP 7.2.0+) `$headers = array('From' => $email, 'Reply-To' => $email);` – Mavelo Oct 04 '18 at 15:38

2 Answers2

0

You can use SMTP server of your email's domain. For example, if you want to use email from Google's Gmail Service as From address , you have to use the Gmail SMTP server.

So, you can add SMTP email rely for SendMail. How to do it you may read here

Also, you can install SMTP client msmtp and configure PHP for using it. Instructions here

At last, if you don`t want to configure your server, you can use PHPMailer library.

Jekys
  • 313
  • 1
  • 8
0

It's because the mailserver you're using to send your email does not belong to the domain of the sender, and is therefore not a 'trusted' source.

vogomatix
  • 4,856
  • 2
  • 23
  • 46