Jump to content

Recommended Posts

I need some help finishing this up. I am able to send SMS via email address just fine, I would like to be able to use a reply-to address of the cell phone to allow them to respond back to each other via cell phone once conversation is initiated by the email. This should be fairly easy but I am not getting any closer. Like I said, this works but does not set a valid reply-to or return-path. Any help would be appreciated.

Here is the form....

<form method="post" action="sms.php">
Recipient Name: <input type="text" name="nameto"><br>
Destination Cell Phone: <input name="phone" type="text"><br>
Destination Service Provider: <select name="carrier">
<option value="message.alltel.com">Alltel</option>
<option value="txt.att.net">AT&T</option>
<option value="myboostmobile.com">Boost Mobile</option>
<option value="sms.mycricket.com">Cricket Wireless</option>
<option value="messaging.nextel.com">Nextel</option>
<option value="messaging.sprintpcs.com">Sprint</option>
<option value="tmomail.net">T-Mobile</option>
<option value="vtext.com">Verizon</option>
<option value="vmobl.com">Virgin Mobile</option>
<option value="mymetropcs.com">MetroPCS</option>
<option value="gscsms.com">Golden State Cellular/option>
<option value="cingular.com">Cingular</option>
<option value="qwestmp.com">Qwest Wireless</option>
<option value="mmst5.tracfone.com">TracFone</option>
<option value="utext.com">Unicel</option>
<option value="email.uscc.net ">US Cellular</option>
<option value="mobile.gci.net">GCI (Alaska)</option>
<option value="cwemail.com">Centennial Wireless</option>
<option value="msg.acsalaska.com">Alaska Communication Systems</option>
</select><br>
Your Name: <input type="text" name="name"><br>
Your Cell Phone: <input name="phone1" type="text"><br>
Your Carrier: <select name="carrier1">
<option value="message.alltel.com">Alltel</option>
<option value="txt.att.net">AT&T</option>
<option value="myboostmobile.com">Boost Mobile</option>
<option value="sms.mycricket.com">Cricket Wireless</option>
<option value="messaging.nextel.com">Nextel</option>
<option value="messaging.sprintpcs.com">Sprint</option>
<option value="tmomail.net">T-Mobile</option>
<option value="vtext.com">Verizon</option>
<option value="vmobl.com">Virgin Mobile</option>
<option value="mymetropcs.com">MetroPCS</option>
<option value="gscsms.com">Golden State Cellular/option>
<option value="cingular.com">Cingular</option>
<option value="qwestmp.com">Qwest Wireless</option>
<option value="mmst5.tracfone.com">TracFone</option>
<option value="utext.com">Unicel</option>
<option value="email.uscc.net ">US Cellular</option>
<option value="mobile.gci.net">GCI (Alaska)</option>
<option value="cwemail.com">Centennial Wireless</option>
<option value="msg.acsalaska.com">Alaska Communication Systems</option>
</select><br>
Subject: <input type="text" name="subject"><br>
Message:<br>
<textarea name="msg" rows="15" cols="40"></textarea><br>
<input type="submit">
</form>

And here is the sms.php that processes the form.

  <?php
  $phoneB = $_REQUEST['phone1'];
  $toB = $_REQUEST['carrier1'];
  $nameto = $_REQUEST['nameto'];
  $phone = $_REQUEST['phone'];
  $to = $_REQUEST['carrier'];
  $sendto = "$phone@$to";
  $from = "support@pccreditnow.com";
  $fromcell = "$phoneB@$toB";
  $namefrom = $_REQUEST['name'];
  $subject = $_REQUEST['subject'];
  $message = $_REQUEST['msg'];

  authSendEmail($from, $namefrom, $sendto, $nameto, $subject, $message);

  //Authenticate Send - 21st March 2005
  //Revised - 30th August 2010 by Kevin Loring to send SMS
  //This will send an email using auth smtp and output a log array
  //logArray - connection,

  function authSendEmail($from, $namefrom, $sendto, $nameto, $subject, $message)
  {
  //SMTP + SERVER DETAILS
  /* * * * CONFIGURATION START * * * */
  $smtpServer = "smtp.mailserver.com";
  $port = "25";
  $timeout = "30";
  $username = "email@somehwere.com";
  $password = "passwqord";
  $localhost = "localhost";
  $newLine = "\r\n";
  /* * * * CONFIGURATION END * * * * */

  //Connect to the host on the specified port
  $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  $smtpResponse = fgets($smtpConnect, 515);
  if(empty($smtpConnect))
  {
  $output = "Failed to connect: $smtpResponse";
  return $output;
  }
  else
  {
  $logArray['connection'] = "Connected: $smtpResponse";
  }

  //Request Auth Login
  fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['authrequest'] = "$smtpResponse";

  //Send username
  fputs($smtpConnect, base64_encode($username) . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['authusername'] = "$smtpResponse";

  //Send password
  fputs($smtpConnect, base64_encode($password) . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['authpassword'] = "$smtpResponse";

  //Say Hello to SMTP
  fputs($smtpConnect, "HELO $localhost" . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['heloresponse'] = "$smtpResponse";

  //Email From
  fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['mailfromresponse'] = "$smtpResponse";

  //Email To
  fputs($smtpConnect, "RCPT TO: $sendto" . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['mailtoresponse'] = "$smtpResponse";

  //The Email
  fputs($smtpConnect, "DATA" . $newLine);
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['data1response'] = "$smtpResponse";

  //Construct Headers
  $headers = "MIME-Version: 1.0" . $newLine;
  $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
  $headers .= "To: $nameto <$sendto>" . $newLine;
  $headers .= "From: $namefrom <$from>" . $newLine;
  $headers .= "Reply-To: $fromcell <$fromcell>" . $newLine;
  $headers .= "Return-Path: $fromcell <$fromcell>" . $newLine;

  fputs($smtpConnect, "To: $sendto\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
  $smtpResponse = fgets($smtpConnect, 515);
  $logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
//insert var_dump here for testing purposes
//var_dump($logArray);
echo "<center><a href='index.htm'><img src='img/logo.png' border='0'></a></center>";
echo "<p>HEY!<br>";
echo "$namefrom, you have sent a message using my SMS system<br>";
echo "Your cellphone $phoneB via email address <a href='$fromcell'>$fromcell</a> was used as the replyto address<br>";
echo "Subject: $subject<br>";
echo "Message sent: $message<br>";
echo "Sent to $nameto's cell phone $phone via email address <a href='$sendto'>$sendto</a><br>";
echo "</p></p>";
echo "<center>Would you like to do it again?<br><a href='index.htm'>Yes</a> or <a href='http://www.facebook.com'>No</a></center>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/212288-need-help-with-email-to-sms/
Share on other sites

Off topic (and does not solve the issue).

 

You will want to add an array on the PHP side of all the carriers and then validate the $to against that (via in_array). If you do not, this could easily be turned into a spamming email system. I would also validate that the $phone value is all numbers as well. Simple steps to help prevent spam!

For the sake of simplifying the code I left out the captacha and validation rules. You are right though, and I appreciate the heads up, but I'm on top of that already.

This is for an app on facebook, which includes POST protection of variables as well. Not foolproof but every bit helps.

 

I like your idea about validating the $to against an array, I think I'll add that as well.

 

As far as getting the Reply-To and Return-Path working correctly, I am stumped. It must be staring me in the face but I can't see it. I'm sure someone can easily fix if they have a little experience with authenticated SMTP email. Anyone? Anyone?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.