8 replies
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
#@@@help #mail@@@ #php
  • Profile picture of the author djape
    Try this:

    $email = "email@example.com";
    $subject = "My Subject";

    $header = 'MIME-Version: 1.0'."\r\n";
    $header .= 'Content-type: text/html;charset=iso-8859-1'."\r\n";
    $header .= "Reply-To: My Name <myemail@example.com>\r\n";
    $header .= "Return-Path: My Name <myemail@example.com>\r\n";
    $header .= "From: My Name <myemail@example.com>\r\n";
    $header .= "Organization: MyOrganization \r\n";
    $body = "HTML MESSAGE BODY HERE";

    mail($email,$subject,$body,$header);
    {{ DiscussionBoard.errors[10627274].message }}
    • Profile picture of the author rachidspot
      Originally Posted by djape View Post

      Try this:

      = "email@example.com";
      = "My Subject";

      = 'MIME-Version: 1.0'."rn";
      .= 'Content-type: text/html;charset=iso-8859-1'."rn";
      .= "Reply-To: My Name <myemail@example.com>rn";
      .= "Return-Path: My Name <myemail@example.com>rn";
      .= "From: My Name <myemail@example.com>rn";
      .= "Organization: MyOrganization rn";
      = "HTML MESSAGE BODY HERE";

      mail(,,,);

      Thank you for your reply

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

      $from=$_POST['from'];
      $headers .= 'From: $from' . "\r\n";
      {{ DiscussionBoard.errors[10629248].message }}
  • Profile picture of the author djape
    $from=$_POST['from'];
    $headers .= "From: ".$from." <some@email.here>\r\n";
    {{ DiscussionBoard.errors[10629450].message }}
  • Profile picture of the author rachidspot
    I try this but not works, plz I want to set the From name as a input, this is the code:

    <?php

    $to=$_POST['to'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];

    $From=$_POST['From'];

    $headers .= 'From: $From' . "\r\n";

    $headers .= "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=ISO-8859-1" . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
    $headers .= 'Reply-To: mailhere' . "\r\n";


    if($_POST['submit']) {

    mail($to,$subject,$message,$headers);

    echo "message sent";
    }


    ?>
    [/B]
    {{ DiscussionBoard.errors[10630656].message }}
  • Profile picture of the author djape
    Try this:

    <?php
    if(isset($_POST['submit'])) {
    $to=$_POST['to'];
    $subject=$_POST['subject'];
    $message=$_POST['message'];
    $From=$_POST['From'];
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=ISO-8859-1" . "\r\n";
    $headers .= "From: ".$From." <some@email.here>\r\n";
    $headers .= "Reply-To: My Name <myemail@example.com>\r\n";
    mail($to,$subject,$message,$headers);
    echo "message sent";
    }else{
    //Your form here
    }
    ?>
    {{ DiscussionBoard.errors[10630815].message }}
    • Profile picture of the author rachidspot
      Yes, it's working now, I can put any From name I want, Thank you

      plz How can I add received and returnpath ?
      {{ DiscussionBoard.errors[10632685].message }}
  • Profile picture of the author djape
    $headers .= "Return-Path: some@email.here\r\n";
    {{ DiscussionBoard.errors[10632693].message }}
  • Profile picture of the author rachidspot
    hmm, not worked
    {{ DiscussionBoard.errors[10634497].message }}

Trending Topics