2

These are my headers:

$defaultHeaders  = 'MIME-Version: 1.0' . "\r\n";
$defaultHeaders .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$defaultHeaders .= 'From: Kyote Productions <no-reply@' . $_SERVER['SERVER_NAME'] . '>' . "\r\n";
$this->headers = (!empty($headers)) ? $headers : $defaultHeaders;

These are my subject, message and recipient:

$this->subject = $subject;
$this->message = $message;
$this->to = $recipient;

I am sending the mail like this:

return mail($this->to, $this->subject, $this->message, $this->headers);

When I write a method to var_dump() all these results they look like this:

array(4) {
  [0]=>
  string(39) "x@outlook.com,z@gmail.com,"
  [1]=>
  string(18) "PHP Mailer by Kyle"
  [2]=>
  string(187) "<html><head><title>PHP Mailer by Kyle</title></head><body><img style="width: 100%; height: 200px;" src="http://wallpapercave.com/wp/Qom1Iwe.jpg"><br /><br />Test email baby!</body></html>"
  [3]=>
  string(112) "MIME-Version: 1.0
Content-type: text/html; charset=UTF-8
From: Kyote Productions <no-reply@kyoteprod.x10.mx>
"
}
1

Error reporting is on, but I receive no errors and it returns 1 when I run this:

echo (int)$obj->sendMail();
Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • Mail function simply passes mail to the smtp or postfix server you have installed on the machine. If the message was passed successfully it returns true. PHP has no way of tracking how the mail server behaves. You can use some library to use smtp server you use for your actual mail or use service like mailchimp or sendgrid to send mails from your application. – Zefiryn Oct 21 '16 at 21:13
  • It was working perfectly a few days ago, I made a few recursions to it and now it just won't send (maybe the headers are broken?) @Zefiryn – Jaquarh Oct 21 '16 at 21:15
  • Revert the recursions – Mike B Oct 21 '16 at 21:18
  • Didn't back-up, silly of me ino @MikeB – Jaquarh Oct 21 '16 at 21:19
  • go look at the mail server's error log. if mail returns true, then PHP's job is done. That job is basically the equivalent of walking an envelope down to the street corner and tossing it into the mailbox. If the letter goes into the box, PHP is done. If the mailbox is then nailed by a drunk driver, or the post service loses the letter, that's not PHP's problem. – Marc B Oct 21 '16 at 21:25
  • Also, just took one quick peek at an actual email, the only difference I see is quotes around utf-8 and lowercase utf, but that seems unlikely to solve your problem, though you never know. – jhaagsma Oct 21 '16 at 21:29
  • 1
    There is also a possibility that everything works fine, the email is passed by php and send by the mail server but the recipient server rejects it and not even show it at spam folder. I just has similar problem when I used a Zend 1 based app to send confirmation emails from gmail account. It stopped working and it turned out that gmail smtp server treats my connection as unsafe because are done by an outdated application. You can get caught in something similar when mail server will treat the incoming mail as a low level spam that is not worth showing to the recipient. – Zefiryn Oct 21 '16 at 21:29
  • Its free hosting don't have access to any of it, I think there email servers are down, not even a normal mail(); quick one is working – Jaquarh Oct 21 '16 at 21:30

1 Answers1

0

Do you have a mail server installed?

As per the php.net mail page: "It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination."

I'd also point out this question about sending mail with php, and this question about sending mail on linux.

You could also try using the PHPMailer class rather than rolling your own; it's pretty handy.

Community
  • 1
  • 1
jhaagsma
  • 2,414
  • 2
  • 24
  • 26
  • I'm using the x10hosting for testing and it was working before I added some edits to the header allowing HTML and changed some object methods – Jaquarh Oct 21 '16 at 21:18
  • If you're not too attached to this bit of code, perhaps try using PHPMailer? It handles a lot of these things very nicely and automatically. – jhaagsma Oct 21 '16 at 21:22