0

I've been havin some troubles with emails not arriving on some addresses, or to be more specific, so some domains (for exampel gmx.com). The emails arrives as they should on some domains, though (for example spray.se or gmail.com).

I've checked and our server IP seems to be all good. No blocks found anywhere.

Is there any critical problem with my code?

$mail_body = "Välkommen till ***!\n\nOm du ej registrerat dig på *** ber vi dig bortse från\ndetta mail.\n\nDin aktiveringskod är:\n" . $activation . "\n\nMvh\nVi på ***"; // Mail body
$subject = "Din aktiveringskod";
$header = "From: *** <no-reply@***.se>\r\n";

ini_set('sendmail_from', 'no-reply@***.se'); // Snabbfix på problem med IIS (5+?)

if(!mail($recipient, $subject, $mail_body, $header)) die ("mail error");

If the email is delivered, there are no errors in it!

I've also tried utf8-encode the whole thing, but that doesn't change anything.

Regards!

Christian Lundahl
  • 2,000
  • 3
  • 18
  • 29

3 Answers3

0

Your header should be like this

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers.='From: *** <no-reply@***.se>\r\n';
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
0

Sounds like your emails are being identified as spam by some servers, this could mean they end up in the spambox or are being prevented from being delivered all together (on the more ruthless receivers). Or are you absolutely positive they're being sent in the first place? Check your logs if you can.

Anyway, there are few things you can do to lessen the chance of your emails being identified as spam:

  • Fully flesh out Headers, eg:

    $headers .= "Reply-To: The Sender <sender@sender.com>\r\n";
    $headers .= "Return-Path: The Sender <sender@sender.com>\r\n";
    $headers .= "From: The Sender <senter@sender.com>\r\n";
    $headers .= "Organization: Sender Organization\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/plain; charset=utf-8\r\n";
    etc...
    
  • Make sure the message sender domain in the email & server domain match

  • Correctly use the content type attribute

You can also double check that your server isn't blacklisted, but it sounds like you've done this anyway.

I'd also recommend not using the PHP mail function, try swift mailer or PHPMailer, or scout around and find one that suits your needs.

SubjectCurio
  • 4,702
  • 3
  • 32
  • 46
0

The problem wasn't related to the topic at all. It was a DNS error that caused this.

Christian Lundahl
  • 2,000
  • 3
  • 18
  • 29
  • I am experiencing similar issue. We've recently shifted our hosting and facing this problem. Can you indicate what was the DNS error and how exactly you fixed it. Thanks – user2436428 Oct 16 '16 at 17:00
  • @user2436428 I'm sorry but this was four years ago and I don't remember. I should have written it down at that time, I guess. – Christian Lundahl Nov 04 '16 at 08:43