0

My mail script is only sending mail when the headers aren't set. I'm using the same code on two different servers, it works on one but not the other. The one it doesn't work on is a WordPress site hosted on Siteground if that makes any difference. Even when it doesn't send, it always comes up as a 'success'. Does anyone know what I can do? I was hoping to find some kind of mail error logs, but I can't seem to locate them. I've tried it with just the email as the header but still doesn't work.

$headers = array("From: " . $name . '<' . $email . '>',
                "Reply-To: " . $name . '<' . $email . '>',
                "X-Mailer: PHP/" . PHP_VERSION,
                "MIME-Version: 1.0",
                 "Content-type: text/html; charset=iso-8859-1"
            );

            $headers_buyer = implode("\r\n", $headers);

if(mail($admin_email, $subject, $message, $headers_buyer))
                    {
                        echo "Success";
                    }
                    else
                    {
                        echo "Failure";
                    }
user1375823
  • 95
  • 1
  • 12
  • 2
    You should contact the support of the company that hosts your website. If the PHP function [`mail()`](http://php.net/manual/en/function.mail.php) returns "success" then there is not a problem in your code, it's something else that prevents the emails to be sent. And the webhoster is the most appropriate place to ask what's wrong. – axiac Jun 20 '15 at 16:29

1 Answers1

2

I would recommend you to use PhpMailer instead of the native mail function.

You will get a more detailed trace of what is going on and it is in my humble opinion the best way to send emails with PHP.

If you still have problems, try using PhpMailer with a free account of Mandrill or Sendgrid. Both of them are Transactional Email services, that allow you to send until 12.000 emails per month with no charges, and with high deliverability results.

2017 September edit

I correct my answer, now only Sendgrid is possible to use freely, with a maximum of 100 emails/day. Still quite nice to start with.

xarlymg89
  • 2,552
  • 2
  • 27
  • 41