SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast earph's Avatar
    Join Date
    May 2004
    Location
    Austin
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Put Form Data in Email "From" Field?

    I have the form script below, but I need to have the "$subscribe" data show up in the "From" field when I get an email in Outlook. I'm sure it has something to do with the header, but how do I set it up?
    Code:
    <?php
       // Get data from form
       $subscribe = $_POST['subscribe']; 
    
       // Set mail recipient and subject
       $to = "matt@earph.com";
       $subject = "Add to Newsletter";
    
    // Set standard header
    
       $headers = "Content-Type: text/html\n\n";
       $message = printMessage($email);
    
       mail($to, $subject, $message, $headers);
       header("Location: thanks.html"); 
    
    
       #############################
       ######### Functions #########
       #############################
    
       function printMessage($email)
       // Preconditions:  None
       // Postconditions: Prints out data from the form formatted in HTML
       {
          $messageOut = "$email";
    
          return $messageOut;
       } 
    ?>

  2. #2
    SitePoint Wizard holmescreek's Avatar
    Join Date
    Mar 2001
    Location
    Northwest Florida
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Quote Originally Posted by bigskillet
    I have the form script below, but I need to have the "$subscribe" data show up in the "From" field when I get an email in Outlook. I'm sure it has something to do with the header, but how do I set it up?
    Code:
    <?php
       // Get data from form
       $subscribe = $_POST['subscribe']; 
    
       // Set mail recipient and subject
       $to = "matt@earph.com";
       $subject = "Add to Newsletter";
    
    // Set standard header
    
       $headers = "Content-Type: text/html\n\n";
       $message = printMessage($email);
    
       mail($to, $subject, $message, $headers);
       header("Location: thanks.html"); 
    
    
       #############################
       ######### Functions #########
       #############################
    
       function printMessage($email)
       // Preconditions:  None
       // Postconditions: Prints out data from the form formatted in HTML
       {
          $messageOut = "$email";
    
          return $messageOut;
       } 
    ?>
    Hi, give this a shot :

    $sender = "sender@email.com";
    $headers = "Content-Type: text/html\r\n";
    $headers .= "From : $sender\r\n";


    Do a google on : php mail() function it has lots of info on creating the mail headers including more advanced headers like cc, bcc etc.
    intragenesis, llc professional web & graphic design

  3. #3
    SitePoint Enthusiast earph's Avatar
    Join Date
    May 2004
    Location
    Austin
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I managed to get it to work like this:
    Code:
    <?php 
    $message = "$email\n";
    
    $to = "matt@earph.com"; 
    $subject = "Add to Newsletter"; 
    $mailheaders = "From: $email <> \n"; 
    $mailheaders .= "Reply-To: $email\n\n"; 
    mail($to, $subject, $message, $mailheaders); 
    include("thanks.html"); 
    
    ?>
    Only problem is, Outlook is now throwing these emails into the "junkmail" folder. I've used the script above many times, but this has never happened before. Is there a setting that is doing this?

    Well, I'm good for now i guess. I just really liked the other script because it allowed me to print in formatted HTML.

    Thanks!

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2005
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigskillet
    I just really liked the other script because it allowed me to print in formatted HTML.
    Thanks!
    this should get you your html

    $mailheaders = "Content-Type: text/html\n\n";
    $mailheaders .= "From: $email <> \n";
    $mailheaders .= "Reply-To: $email\n\n";

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For more options (i can see, you will need) you can try to use XPertMailer (it is a PHP class feture) to send your e-mails. Check this: www.xpertmailer.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •