I recently set up an alert system whereby when certain APIs are called, it alerts me (or others) via PHP's mail() function.
On email's it works totally fine. The function returns true and it is received in the mailbox where it is sent to.
For some reason when sending to an SMS gateway (i.e. XXXXXXXXXX@messaging.sprint.com) the function sends it (it does return true) however it never gets received on the other end.
If I take that same exact email address (that goes to an sms gateway) and send it via an email client (such as zimbra or whatever), it goes through fine and it is received by the person.
I am the web designer and not really the email / IT person. I am assuming it has something to do with headers or something along this line, however I am not versed on this technical subject.
I spoke to my IT guy and he said that it is erroring and looks like there is no proper "From" address in the headers. Instead of coming from a valid email address, the email errors and looks like it is coming from "www.data@[server-name]" instead of what I am sending via the header which is a valid email address.
here is a snippet of my code:
<?php
$carriers = array("@messaging.sprintpcs.com");
//get to email
if (isset($_POST['to'])) {
$to = $_POST['to'];
}
// get from email
if (isset($_POST['from'])) {
$from = $_POST['from'];
$fromHeader = "From: ".$from."\r\n Sender: ".$from."\r\n";
}
// get subject
if (isset($_POST['subject'])) {
$subject = $_POST['subject'];
}
// get message
if (isset($_POST['message'])) {
$message = $_POST['message'];
}
// get cc
if (isset($_POST['cc'])) {
if ($_POST['cc']!="") {
$ccHeader = "CC: ".$_POST['cc']."\r\n";
}
else {
$ccHeader="";
}
}
else {
$ccHeader="";
}
// get bcc
if (isset($_POST['bcc'])) {
if ($_POST['bcc']!="") {
$bccHeader = "Bcc: ".$_POST['bcc']."\r\n";
}
else {
$bccHeader="";
}
}
else {
$bccHeader="";
}
// get reply to
if (isset($_POST['replyTo'])) {
if ($_POST['replyTo']!="") {
$replyToHeader = "Reply-To: ".$_POST['replyTo']."\r\n";
}
else {
$replyToHeader="";
}
}
else {
$replyToHeader="";
}
$additionalHeaders = "Content-Type: text/plain; charset=\"utf-8\" Content-Transfer-Encoding: 8bit \r\n";
$headers = $fromHeader.$ccHeader.$bccHeader.$additionalHeaders;
foreach ($carriers as $carrier) {
$number = get_numeric_only($to).$carrier;
if (mail($to,$subject,$message,$headers)) {
$response = array("response" => "SUCCESS");
}
else {
$response = array("response" => "ERROR");
}
}
echo json_encode($response);
?>
edit:
I changed the mail() function by adding a 4th parameter so it looks like this as apparently this would help:
mail($to,$subject,$message,$headers,'-f[myaddress]@[mydomain].com')
Then the sms-email bounced BACK to the "from" email address as stated in the headers with the following:
The original message was received at Wed, 28 Jan 2015 19:10:32 -0500
from localhost [127.0.0.1]
----- The following addresses had permanent fatal errors -----
<xxxxxxxxxx@messaging.sprintpcs.com>
(reason: 550 Host unknown)
----- Transcript of session follows -----
550 5.1.2 <xxxxxxxxxx@messaging.sprintpcs.com>... Host unknown (Name server: messaging.sprintpcs.com: host not found)
Does this jog anybody's head? .....