1

I am using the following code to send email from my website:

<?php

$to = "mygmail@gmail.com;
$subject = "My Site - NoReply";
$headers = "From: do not reply @ My Site" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "You have received a message from the My site: <br /><br />";
$message .= "Greetings <strong>My Name</strong>, <br /><br />";
$message .= "You have been granted access to the My site.<br /><br />";
                    
mail($to, $subject, $message, $headers);

?>

My site is being hosted by Hostgator. They have advised me that I should use port 465 for SMTP.

I just finished chatting with them. Everything is set on their end, and there is nothing additional that they can do.

With that said, why am I unable to send the email using the above?

I've used this same code on my job, which uses an Apache server, and I have no problems sending any email from a website.

What am I missing to make this work?

John Beasley
  • 2,577
  • 9
  • 43
  • 89
  • this question may contain some insights https://stackoverflow.com/questions/18535294/mail-not-sending-with-phpmailer-over-ssl-using-smtp – j4g0 Sep 09 '20 at 04:49

1 Answers1

0

The most obvious problem here is that you're not using SMTP.

PHP's mail() function works by submitting a message to a sendmail binary via a shell, and does not use the network directly at all, so you have no way of doing what they asked.

Sending through SMTP, even to localhost, is preferable to using mail() because it's faster, safer, and more reliable.

You tagged this question with PHPMailer, which can send through SMTP directly, and @j4g0 provided a link to a reasonable implementation of that. There are many more examples both here on SO and in the PHPMailer project.

Synchro
  • 35,538
  • 15
  • 81
  • 104