Help with php mail()........................@@@

Discussion in 'PHP' started by Rachidspot, Apr 4, 2016.

  1. #1
    Hi Everybody

    Please I want to know how can I specify header parameters using mail() function

    I want to set and usemy own email header, plz tell me how can I do it? like specify "From Name", "Mail From", "Reply-To", "Returnpath", etc..

    now I can set just: to, message, subject

    Thank a lot
     
    Rachidspot, Apr 4, 2016 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You define the headers ahead of calling the mail()-function, and then just pass in the $headers-variable. Read up on php.net: http://php.net/manual/en/function.mail.php

    Oh, and please don't use subject lines like that. DON'T use @@----- and so on.
     
    PoPSiCLe, Apr 4, 2016 IP
    sarahk likes this.
  3. Rachidspot

    Rachidspot Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Thank you for your reply

    plz how can I set the From input as I want ? I use this code but not works:

    $from=$_POST['from'];


    $headers .= 'From: $from' . "\r\n";
     
    Rachidspot, Apr 9, 2016 IP
  4. sajjadhira

    sajjadhira Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    Use this this simple code,
    <?php
    $tomail = 'tomail@example.com';
    $from = 'PHPAns <admin@yourdomain.com>';
    $subject = 'PHP Mail Check';
    $headers = 'MIME-Version: 1.0\r\n';
    $headers.='Content-type: text/html; charset=iso-8859-1\r\n';
    $headers.='From: '.$from.'r\n\';
    $message.='Mail Message...';
    $mailsent = mail($to, $subj, $message, $headers);
    mail($tomail, $subject, $message, $headers);
    ?>
    PHP:
     
    sajjadhira, May 27, 2016 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,807
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #5
    1. If you aren't getting what you expect do a var_dump($headers); to see what is actually in the variable
    2. Use 'single quotes' if you want exactly that string and you don't want PHP to mess with it
    3. Use "double quotes" if you want PHP to look inside the string for a variable to parse
    4. To have total control with "double quotes" use {} around the variable - and with arrays you have to or it just won't work
    Therefore the line I've quoted should have been
    $headers .= "From: {$from}\r\n";
    Code (markup):
    or the way @sajjadhira put it
    $headers.='From: '.$from.'r\n\';
    Code (markup):
     
    sarahk, May 27, 2016 IP
  6. sajjadhira

    sajjadhira Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #6
    @sarahk sir, thank you for your valuable comment.
     
    sajjadhira, May 28, 2016 IP
  7. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #7
    Sir? When did Sarah change her plumbing?
     
    mmerlinn, May 28, 2016 IP
  8. sajjadhira

    sajjadhira Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #8
    sorry! my mistake, she is madam :):) , sarahk & mmerlinn I apologize for the mistake. :(
     
    sajjadhira, May 28, 2016 IP
  9. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #9
    I accept your apology and I am sure @sarahk will, too.

    However, due to negative connotations of "madam" I am not sure Sarah would like to be called a Madam either..
     
    mmerlinn, May 28, 2016 IP
  10. sajjadhira

    sajjadhira Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #10
    There are no negative connotations of "madam" in my country, "madam" is a respected word in here, I hope Sarah will accept it. :) @mmerlinn
     
    sajjadhira, May 28, 2016 IP
  11. sarahk

    sarahk iTamer Staff

    Messages:
    28,807
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #11
    @sajjadhira it's all good. @mmerlinn is teasing - after all he's from the country where people say "Yes ma'am" and call their father "sir"
    Generally though "a madam" runs a whore house and I definitely don't do that!
     
    sarahk, May 28, 2016 IP
    mmerlinn likes this.