0

I've got a website where people can register and need to validate in ordre to use their account. Unfortunately, some people are not receiving the confirmation mail..

here's the code I'm using

function mail_send($arr) {
    if (!isset($arr['to_email'], $arr['from_email'], $arr['subject'], $arr['message'])) {
    throw new HelperException('mail(); not all parameters provided.');
}

$to            = empty($arr['to_name']) ? $arr['to_email'] : '"' . mb_encode_mimeheader($arr['to_name']) . '" <' . $arr['to_email'] . '>';
$from        = empty($arr['from_name']) ? $arr['from_email'] : '"' . mb_encode_mimeheader($arr['from_name']) . '" <' . $arr['from_email'] . '>';

$headers    = array
(
    'MIME-Version: 1.0',
    'Content-Type: text/html; charset="UTF-8";',
    'Content-Transfer-Encoding: 7bit',
    'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
    'Message-ID: <' . $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['SERVER_NAME'] . '>',
    'From: ' . $from,
    'Reply-To: ' . $from,
    'Return-Path: ' . $from,
    'X-Mailer: PHP v' . phpversion(),
    'X-Originating-IP: ' . $_SERVER['SERVER_ADDR'],
);

    mail($to, '=?UTF-8?B?' . base64_encode($arr['subject']) . '?=', $arr['message'], implode("\n", $headers));
}

$arr = array();
$arr['to_email'] = $mail;
$arr['from_email'] = "no-reply@website.com";
$arr['subject'] = "Welcome [Validation]";
$arr['message'] = 'Thank you for registering, you're now able to fully use this website.'."<br><br>".'Username: <b>'.$username.'</b> Password :<b>'.$password.'</b>.'."<br><br>".' You need to validate in order to login...'."<br>".'<a href="a">Validate!</a>'."<br><br>".'Have fun!'."<br><br>".'--- The team.'; 

mail_send($arr);

Also, I've got forum cms (phpbb and mybb) running great on the same server with 0 problem related to email..

So what's wrong with my code...

Thank you!

cloud1250000
  • 45
  • 1
  • 8
  • 2
    It is possible there are numerous variables outside your control that effect whether someone receives your email. – lagbox Oct 05 '14 at 17:46
  • Short answer: rolling your own code is a recipe for invalid message structure and formatting. Use a library. – Synchro Oct 05 '14 at 19:01
  • I'm using phpmailer now, but I receive a lot of error.. I bet it's because they didn't put the right email.. – cloud1250000 Oct 06 '14 at 20:41

2 Answers2

2

I would suggest to look into a mailer class for php like this one https://github.com/PHPMailer/PHPMailer

saves you a lot of headaches

Jelle Keizer
  • 723
  • 5
  • 9
0

I can see nothing wrong with your code, if there were I think even the half will not be getting any mail. I advise you contact your Hosting provider Customer Service for this one.

Sameer Shemna
  • 886
  • 10
  • 19
  • But how can my forums installation have a 100% reaching rate.. – cloud1250000 Oct 05 '14 at 17:50
  • Buddy there might be a limit set upon you by the Hosting provider, please recheck. If they told you it is unlimited, then there is definitely a limit and that too a small one. – Sameer Shemna Oct 05 '14 at 17:53
  • Your code possibly missing important headers or sending headers that are blocked by some mailservers, also your from address is very spam sensitive. – Jelle Keizer Oct 05 '14 at 17:56
  • I see, what's a good "from email" then? Also, I'll contact my host to check if there's any limit.. – cloud1250000 Oct 05 '14 at 17:58
  • I am not getting paid for this but I will advise using a Mass mail service like Mailchimp http://mailchimp.com/ for sending mass emails. – Sameer Shemna Oct 05 '14 at 18:03
  • Use the domain of where this script is running from and make sure mail has been setup on the dns for that domain. and no-reply isn't a very good choice, better use a real existing email address where people actually can reply to. – Jelle Keizer Oct 05 '14 at 18:04