0

I am trying to send text messages to my phone from my server using php. I recently configured the server to send email, which it does (verified). It, however, goes into my spam box. When I try to send a message via sms I do not receive anything.

This is the script I am using:

$to = "myemailaddress@gmail.com";
$subject = "testing";
$body = "";
$headers = 'From: testemailaddress@gmail.com';

if (mail($to, $subject, $body, $headers)) {
    echo("<p>Message successfully sent!</p>"); 
} else {
    echo("<p>Message delivery failed...</p>");
}

The address that I am using for sms is myphonenumber@txt.att.net in the 'To' field.

I am going to go out on a limb here and say this is a authentication issue, maybe.

Is there anything I need to configure further? (i.e. php.ini)

mtlca401
  • 1,413
  • 4
  • 16
  • 24
  • can you send a sms to that address using your regular email client? email to txt gateways work in a variety of ways, you should check the docs of the host. –  Jun 22 '11 at 23:40
  • Had the same problem a while ago. It most likely goes to your spambox because you set the From: to ..@gmail.com, while your sending server is something like localhost. try setting the From: to noreply@yourdomain and set an additional "Reply-To:whatever@gmail.com" – iHaveacomputer Jun 22 '11 at 23:50

1 Answers1

1

Most email providers/servers today rely heavily on spam filtering / dnsbl. Your webserver is not a know mail server, and you probably did not set up SPF or anything.

An approach to avoid all those issues would be to utilize a Google Mail address (or any other providers). And instead of the PHP mail function use something more complex like Swiftmailer, which generates Mail headers that are less commonly autoclassified as spam.

See also: Using php's swiftmailer with gmail

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
  • This is what I figured was going on. Not a big deal as long as I can route it trough gmail. First, I'll give Swiftmailer a try. – mtlca401 Jun 22 '11 at 23:51
  • I tried swiftmailer, but could not get it to work. Then, after trying to delete the /var/www/lib/ folder, I accidentally deleted the /lib folder and had to reinstall the whole server. – mtlca401 Jun 24 '11 at 23:16
  • Sorry to hear. If Swiftmailer does not work that easily (it's a matter of configuration), then try PEAR Mail. This has similar capabilities. – mario Jun 24 '11 at 23:23