Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post

    Question PHP Email change "From:" field

    I need a bit of help with a php email I'm creating. Does anyone know how to change the 'from' field in a php form to display a string? For example, when I get emails from Facebook, the word "Facebook" literally shows up in the from field, not an email address.

    The email I'm creating works and sends an attachment as it should, the only issue is with my "from" field. The only issue is that I would like the email to show that it is from "Medical Posters" as opposed to an email address.. but If I put "Medical Posters" in the "from" field in my code and test it, it says the email is from Medical.Posters@phnlgh358.shr.prod.p...cureserver.net. This is not what I'm going for.

    If I put any email address in the from field it gives the email address correctly but this is still not what I'm going for.. Does anyone know how to change the from field to display a Medical Posters (a string)?

    My php code for my email is below..

    PHP Code:
    <?php

    //define the receiver of the email
    $to $_POST[email];
    //define the subject of the email
    $subject 'Medical Posters';
    //create a boundary string. It must be unique
    //so we use the MD5 algorithm to generate a random hash
    $random_hash md5(date('r'time()));
    //define the headers we want passed. Note that they are separated with \r\n
    $headers "From: Medical Posters\r\nReply-To: email@email.com\r\nCc: email@email.com";
    //add boundary string and mime type specification
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
    //read the atachment file contents into a string,
    //encode it with MIME base64,
    //and split it into smaller chunks
    $attachment chunk_split(base64_encode(file_get_contents('poster331.pdf')));
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-mixed-<?php echo $random_hash?> 
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash?>"

    --PHP-alt-<?php echo $random_hash?> 
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    Hello World!!!
    This is simple text email message.

    --PHP-alt-<?php echo $random_hash?> 
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit



    <table width="100%" cellpadding="10" cellspacing="0" bgcolor='#FFFFFF' >

    email content here

    </table>

    --PHP-alt-<?php echo $random_hash?>--

    --PHP-mixed-<?php echo $random_hash?> 
    Content-Type: application/zip; name="poster331.pdf" 
    Content-Transfer-Encoding: base64 
    Content-Disposition: attachment 

    <?php echo $attachment?>
    --PHP-mixed-<?php echo $random_hash?>--

    <?php
    //copy current buffer contents into $message variable and delete current output buffer
    $message ob_get_clean();
    //send the email

    if ($mail_sent = @mail$to$subject$message$headers )) {
        echo 
    $output='sent';
    } else {
        echo 
    $output='not sent';
    }

    ?>
    Any help would be greatly appreciated! Thanks!!

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    239
    Thanks
    1
    Thanked 56 Times in 55 Posts
    PHP Code:
    $headers "From: Medical Posters <webmaster@example.com>\r\n"

  • Users who have thanked gvre for this post:

    KaliK (05-10-2011)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Not sure if this will work, but try: Name <Email> as the from address.

    I think the receiving email server then parses this and uses the Name as the displayed from name - else it uses the email - I think. I can't promise though.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    KaliK (05-10-2011)

  • #4
    New Coder
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post
    This worked! Thank you!!


  •  

    Tags for this Thread

    Posting Permissions

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