Sending a text message from my mail server

Discussion in 'Server Operation' started by bschultz, Jul 30, 2008.

  1. bschultz

    bschultz Member

    I'm trying to send a text message from a php script calling the mail function. All works great...except the top of the sms message says that the message is from [email protected]

    How do I change that to be my email address and not the server name and apache owner?

  2. topdog

    topdog Active Member

    How does your script look like ?
  3. bschultz

    bschultz Member

    It's just a php email sent to all numbers in a database. I was hoping that the header section "From" would override the [email protected] ....but it didn't.

    $text = $_REQUEST["text"];
    //connecto to database
    $dbc = mysql_pconnect('xxx','xxx','xxx'); 
    //select some data
    $sql = "SELECT number FROM texting_numbers"; 
    $dbq = mysql_query($sql,$dbc); 
    //while there are results...
    while ($row = mysql_fetch_array($dbq)) { 
    //build peices of the email message
    $subject = "Subject: subject here";
    $to = "$row[number]";
    $rec = array("[email protected]", "[email protected]", "[email protected]", "[email protected]");
    $headers = 'From: [email][email protected][/email]' . "\r\n" . 'Reply-To: my_number' . "\r\n\n" ;
    //$text = "The text of the message goes here";
    //send the sms email
    foreach ($rec as $r) {
    mail ( "$r, ", " ", "$subject\n\n  $headers $text" );
    //close foreach
    //close while
    echo 'Thank you, your text has been sent...<meta http-equiv=Refresh content=3;url="sendatext.php">';
  4. topdog

    topdog Active Member

    I think you are using the mail function incorrectly. These are the correct options.
    mail($to, $subject, $message, $headers);
  5. bschultz

    bschultz Member

    My code sends the text message just fine...but what I'm trying to change is who the text message is sent from. Any text message sent as an email will come to the cell phone in the format "[email protected]" I want to change that to my email address.

    I'm guessing that I need to change my /etc/hosts file to get rid of the hostname...and also have to change the owner of the webserver from www_data to my email prefix...but I don't know what effects that will have on the rest of the system.
  6. topdog

    topdog Active Member

    Dude you do not seem to understand, there is the actual sender and the envelope sender if you call the mail command properly, then the envelop sender will be set with the correct from address if you want to change your hostname be my guest.
  7. bschultz

    bschultz Member

    I thought that I had read that the text message would always be sent from the Apache owner...I'm sorry. I didn't realize that the header info would override that.

    I'm still having a hard time making this work, though. It still says that the text message is being sent from [email protected]

    Here's the new code...with additional headers set

    $message = $_POST["text"];
    //build peices of the email message
    $to  = 'phone#[email protected]' . ', '; 
    $to .= 'phone#[email protected]';
    $subject = "Subject: My Subject Goes Here";
    $headers .= "Reply-To: myphone#\n";
    $headers .= "From: My Name <[email protected]>\n";
    mail ($to, $subject, $message, $headers); 
    Any ideas?

  8. topdog

    topdog Active Member

    I think it is the system that processes the email to sms that is using the envelop address. Which means to achieve what you want you will have to use the generics system to rewrite the sender system.

    If using sendmail use the generics table and if using postfix use the canonical table.
  9. bschultz

    bschultz Member

    Thanks...that did it!
  10. allmywebsite1

    allmywebsite1 New Member

    you have to use php mail function to send text msg.

Share This Page