I have a question about my php script

Discussion in 'PHP' started by smetten, Oct 6, 2006.

  1. #1
    Hi there,

    I have a sms script (e-mail to sms), but each time I send a message it displays my server name: as sender, can I change this to the name of my site

    Greetz

    Smetten
     
    smetten, Oct 6, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Depends on the script. But look on php.net for the mail() function, you can set the headers, including both the FROM and RETURN address.
     
    T0PS3O, Oct 6, 2006 IP
  3. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Ok thx for your fast reply Tops30

    Greetz

    Smetten
     
    smetten, Oct 6, 2006 IP
  4. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #4
    This is the script i use, can you tell me what I should add, I found lots of stuff on php.net about the mail() function but I can´t seem to get it working on my script...

    Thx in advance

    Greetz

    Smetten

    <?
    
    
      echo '
    
    ';
    
      include 'config.php';
    
    
    
      echo '
    
    ';
    
      if (strtoupper ($code) == substr (strtoupper (md5 ('Mytext' . $sessioncode)), 0, 6))
    
      {
    
      }
    
      else
    
      {
    
       
    
      }
    
    
    
      echo '
    
    ';
    
      $day = date ('mdy');
    
      $ip = gethostbyname ($REMOTE_ADDR);
    
      $checkuses = mysql_num_rows (mysql_query ('' . 'select * from users where ip=\'' . $ip . '\' and day=\'' . $day . '\''));
    
      if ($alloweduses <= $checkuses)
    
      {
    
        echo '<DIV class=front id=content><H1 align=center>This was your last Free Message for today.<br><br>';  
      
    exit('');
      }
    
      else
    
      {
    
        $query = '' . 'INSERT INTO users VALUES (\'' . $ip . '\',\'' . $number . '\',\'' . $day . '\')';
    
        if (!($result = mysql_query ($query)))
    
        {
    
          exit ('Unable to Add IP Entry');
    
          ;
    
        }
    
      }
    
    
    
      echo '
    
    ';
    
      $sql = '' . 'SELECT * FROM carriers WHERE id = \'' . $carrier . '\'';
    
      $result = mysql_query ($sql);
    
      $row = mysql_fetch_array ($result);
    
      $email = $row['email'];
    
      $to = $number . $email;
    
      $headers = 'MIME-Version: 1.0  
    
    ' . 'Content-type: text/html; charset=iso-8859-1
    
    ' . 'To: "Client" <' . $to . '>
    
    ' . 'Date: ' . date ('r') . '
    
    ' . 'Subject: ' . $subject . '
    
    ';
    
      mail ($to, $subject, $message);
    
      echo '
    
    ';
    
      echo '<DIV class=front id=content><H1 align=center>Message sent!</H1><br><p>';
    
      echo '<b>TO:</b> ' . $to . '<br><br>';
    
      echo '<b>SUBJECT:</b> ' . $subject . '<br><br>';
    
      echo '<b>MESSAGE:</b> ' . $message . '<br><br><br><br><br>';
    
      echo ' <p align=center><font size=3><a href=sms.php><span class=navigation1>Send Another Message</span></font></a>';
    
      echo '
    
    ';
    
    ?>
    PHP:
     
    smetten, Oct 6, 2006 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You don't set any FROM in the $headers so it defaults to what's in your Apache's php.ini sendfrom.
     
    T0PS3O, Oct 6, 2006 IP
  6. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Sorry mate,

    But I'm a newbie at this whole php stuff,
    I´ve tried adding the from code to the header part, but each time I tried i get a parsing error. Can you show me what I should add to the code posted in one of my previeous posts on this thread?.

    Thx in advance.

    Smetten
     
    smetten, Oct 6, 2006 IP
  7. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #7
    oh waite I get it now,

    thx
     
    smetten, Oct 6, 2006 IP
  8. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Without seeing the error message and the code you are attempting, it's a bit hard to help. There's not many people who will just write it for you from scratch. It's better to show what you have and we'll fix where you went wrong. Better for learning as well.
     
    T0PS3O, Oct 6, 2006 IP
  9. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #9
    This is the code (form) where people enter the phone number, message and carrier they want to sent too

    <form action="mail.php" method="post">
    
    Mobile Number (to):<br>
    
        <input name="number" size="30" maxlength="30" type="text" class="styled">
    
        <br><br>
    
    
    
    Subject:<br>
    
    <input type="text" name="subject" size="30" class="styled">
    
    <br><br>
    
    Select Carrier:<br>
    
    <select name="carrier" class="styled">
    
      <?
    
    $sql = "SELECT * FROM carriers";
    
    $result = mysql_query($sql); 
    
    while($row = mysql_fetch_array($result)) {
    
    ?>
    
    <option value="<? echo $row["id"]; ?>"><? echo $row["name"]; ?></option>
    
                                    <?
    
    }
    
    ?>
    
    </select>
    
    <br><br>
    
    Enter Message:<br>
    
    <textarea type="text" name="message" rows="4" cols="30" class="styled"></textarea>
    
    <br>
    <br>
    
      <input type="submit" name="Submit" value="send your message">
    </form>
    PHP:
    This is the code that makes sure the e-mails are sent out.
    <?
    
      session_start ();
    
      session_register ('sessioncode');
    
      echo '
    
    ';
    
      include 'config.php';
    
    
    
      echo '
    
    ';
    
      include 'header.php';
    
      echo '
    
    ';
    
      if (strtoupper ($code) == substr (strtoupper (md5 ('Mytext' . $sessioncode)), 0, 6))
    
      {
    
      }
    
      else
    
      {
    
       
    
      }
    
    
    
      echo '
    
    ';
    
      $day = date ('mdy');
    
      $ip = gethostbyname ($REMOTE_ADDR);
    
      $checkuses = mysql_num_rows (mysql_query ('' . 'select * from users where ip=\'' . $ip . '\' and day=\'' . $day . '\''));
    
      if ($alloweduses <= $checkuses)
    
      {
    
        echo '<DIV class=front id=content><H1>Sorry, you have used all of your free messages for today. Come back tomorrow.</H1></div>';
    	include 'footer.php';
        exit ();
    
      }
    
      else
    
      {
    
        $query = '' . 'INSERT INTO users VALUES (\'' . $ip . '\',\'' . $number . '\',\'' . $day . '\')';
    
        if (!($result = mysql_query ($query)))
    
        {
    
          exit ('Unable to Add IP Entry');
    
          ;
    
        }
    
      }
    
    
    
      echo '
    
    ';
    
      $sql = '' . 'SELECT * FROM carriers WHERE id = \'' . $carrier . '\'';
    
      $result = mysql_query ($sql);
    
      $row = mysql_fetch_array ($result);
    
      $email = $row['email'];
    
      $to = $number . $email;
    
      $headers = 'MIME-Version: 1.0
    
    ' . 'Content-type: text/html; charset=iso-8859-1
    
    ' . 'To: "Client" <' . $to . '>
    
    ' . 'Date: ' . date ('r') . '
    
    ' . 'Subject: ' . $subject . '
    
    ';
    
      mail ($to, $subject, $message);
    
      echo '
    
    ';
    
      echo '<DIV class=front id=content><H1>Message sent!</H1><br><p>';
    
      echo 'TO: ' . $to . '<br>';
    
      echo 'SUBJECT: ' . $subject . '<br>';
    
      echo 'MESSAGE: ' . $message . '<br><br>';
    
      echo 'HEADERS: ' . $headers . '<br><br>';
    
      echo 'Click <a href="sms.php">here</a> to go back and send another message.</p></div>';
    
      echo '
    
    ';
    
      include 'footer.php';
    
    ?>
    PHP:
    I know want the sender to be Xorak.com instead of my sever name. How can I do this plz? Can you now show me were i should make the changes?

    Greetz

    Smetten
     
    smetten, Oct 6, 2006 IP
  10. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #10
    A lot of SMS scripts don;t allow you to change the FROM. But just try and get a from in the header as per php's mail() function.
     
    T0PS3O, Oct 6, 2006 IP
  11. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Underneath the "To" line you need
    ' . 'From: ' . . '
     
    mad4, Oct 6, 2006 IP
  12. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #12
    Parse error: parse error, unexpected '@' in /home/content/s/m/e/smetten/html/mail.php on line 347

    This is the error i get when i added your suggestion
     
    smetten, Oct 6, 2006 IP
  13. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #13
    It should be:

    
    ' . 'From: webmaster@example.com
    ' . 'Date: ' . date ('r') . '
    ' . 'Subject: ' . $subject . '
    ';
    PHP:
     
    T0PS3O, Oct 6, 2006 IP
    mad4 likes this.
  14. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #14
    now i don´t get a parsing error but the sender is still my server name, guess it just doesn´t work... sadly enough
     
    smetten, Oct 6, 2006 IP
  15. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #15
    My SMS provider requires a service fee for changing the From. Maybe yours is the same.
     
    T0PS3O, Oct 6, 2006 IP
  16. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #16
    What does your email header look like when it arrives?
     
    mad4, Oct 6, 2006 IP
  17. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #17
    This is the form where users can enter there msg, the carrier and the phone number www.xorak.com/sms.php

    I´ve send one to my hotmail account and this is how it looks like:

    from: <smetten@linhost191.prod.mesa1.secureserver.net>
    send: vrijdag 6 oktober 2006 17:10:33
    too:
    subject: test


    This is a test
     
    smetten, Oct 6, 2006 IP
  18. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Try adding 'reply to' as well:

    'From:
    'Reply-To:

    Hotmail and other big ISPs are known to take the sendfrom value from the php.ini file though. If you really want to change it, yuo might want to hack up that file as well to be sure.
     
    T0PS3O, Oct 6, 2006 IP
  19. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #19
    nah didn´t work either,

    www.xorak.com/sms.php

    if your carrier is in the list can you check what you get as sender?

    Or if your from the US or Canada try the second script on that page.

    I cant try it as i'm from Belgium and our carriers don´t support this method...

    Greetz
     
    smetten, Oct 6, 2006 IP
  20. smetten

    smetten Active Member

    Messages:
    269
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #20
    Anyway, thx for the help guys.

    Smetten
     
    smetten, Oct 6, 2006 IP