-1

I have a WebFaction server and the following code:

$to = "outreach@bmun.org";
$reply_to = "From: " . $_POST['email'];
$name = $_POST['name'];
$subject = "Outreach Request Session for " . $_POST['school'] . " on " . $_POST['date'];

$em = $_POST['message'] . "\n-" . $name;

$sentmail = mail($to, $subject, $em, $reply_to);

$sentmail returns true, but the email is not sending for some reason.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
vishalkal
  • 5
  • 1
  • 1
    The return value of `true` only means that the message was accepted for delivery by the server. Not arriving could mean it has ended up in spam, the server is not correctly configured to send mail, etc. You should probably try serverfault.com instead. – jeroen Jun 18 '14 at 02:11
  • 1
    If the PHP `mail()` function returns `true` then the problem is not with PHP. You should look at your mail server's logs. The mail could also be in a spam folder... – Sverri M. Olsen Jun 18 '14 at 02:13

2 Answers2

1

$sentmail returns true, but the email is not sending for some reason.

The mail function in PHP simply sends the mail via an MTA (mail transfer agent) on the server. A true can just mean the local MTA accepted it. But that is not all you need.

First, does your hosting provider actually allow outgoing mail? Or are messages sent to a virtual “black hole?”

Now, let’s assume that your local MTA—most likely sendmail—works, and the mail jumped off of the server & made it into the real world. Okay, great!

But not so fast…

The thing is just because you send a mail, it doesn’t mean that the receiving end thinks the mail is valid. And chances are the receiving end has decided a random e-mail sent off of a random server is simply SPAM.

I have posted a more detailed answer here, but when it comes to SPAM it basically boils down to this: Do you have an SPF (Sender Policy Framework) record setup for your domain? Do you also have a PTR (reverse DNS) record set for that domain?

If you do not have an SPF or PTR record, the chance of your message simply being flagged as SPAM is quite high.

If you are serious about sending mails off of your server, you need to at least get your SPF record & PTR record set.

Community
  • 1
  • 1
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
-1

You don't have any headers in your email. Although they don't seem to be required, your emails will be blocked by spamcheckers a whole lot sooner.

This is an example:

<?php
        $headers = "MIME-Version: 1.0\n" ;
        $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
        $headers .= "X-Priority: 1 (Highest)\n";
        $headers .= "X-MSMail-Priority: High\n";
        $headers .= "Importance: High\n";

 $status   = mail($to, $subject, $message,$headers);
?> 
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
NoobishPro
  • 2,539
  • 1
  • 12
  • 23
  • saying your sending html email when your not is more likely to get you blocked. –  Jun 18 '14 at 03:08
  • It was just an example of how to use headers. A standard, nothing more. Looking at the poster I assume he'll know what to do with it. – NoobishPro Jun 18 '14 at 03:11