What is the format for e-mail headers that display a name rather than the e-mail?

后端 未结 3 1135
时光取名叫无心
时光取名叫无心 2020-11-29 02:37

I\'m trying to create a php script that will handle a mailing list for me using a mySQL database, and I have most of it in place. Unfortunately, I can\'t seem to get the he

相关标签:
3条回答
  • 2020-11-29 03:12

    Within a single quoted string, only the escape sequences \' and \\ are replaced by ' and \ respectively. You need to use double quotes to have the escape sequences \r and \n to be replaces by the corresponding characters:

    $headers = "From: noreply@rilburskryler.net \r\n";
    $headers.= "Reply-To: noreply@rilburskryler.net\r\n";
    $headers.= "X-Mailer: PHP/" . phpversion()."\r\n";
    $headers.= "MIME-Version: 1.0" . "\r\n";
    $headers.= "Content-type: text/html; charset=iso-8859-1 \r\n";
    $headers.= "BCC: $emailList";
    

    You could also use an array to collect the header fields and put them later together:

    $headers = array(
        'From: noreply@rilburskryler.net',
        'Reply-To: noreply@rilburskryler.net',
        'X-Mailer: PHP/' . phpversion(),
        'MIME-Version: 1.0',
        'Content-type: text/html; charset=iso-8859-1',
        "BCC: $emailList"
    );
    $headers = implode("\r\n", $headers);
    
    0 讨论(0)
  • 2020-11-29 03:20

    To have names, as opposed to email addresses shown, use the following:

    "John Smith" <johnsemail@hisserver.com>
    

    Easy.

    Regarding the broken line breaks, that is because you are enclosing the text in apostrophes rather than quotation marks:

    $headers = array(
      'From: "The Sending Name" <noreply@rilburskryler.net>' ,
      'Reply-To: "The Reply To Name" <noreply@rilburskryler.net>' ,
      'X-Mailer: PHP/' . phpversion() ,
      'MIME-Version: 1.0' ,
      'Content-type: text/html; charset=iso-8859-1' ,
      'BCC: ' . $emailList
    );
    $headers = implode( "\r\n" , $headers );
    
    0 讨论(0)
  • 2020-11-29 03:21
        $to = 'SendersName@domain.com';
        $to .=', ' . $_POST['Femail'];
        $subject = 'Contact Us Form';
    
    // message
    $message ="<html>
    <head>
    <title>Email title</title>
    </head>
    <body>
    <h3>important message follows</h3>
    <div>
         you are being brought this email to be safe.
    </div>
    </body>
    </html>";
    
    
        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        // Additional headers
        $headers .= 'To: SendersEmailName <SendersEmailName@domain.com>' . "\r\n";
        $headers .= 'From: YourName <YourName@domain.com>' . "\r\n";
        $headers.='X-Mailer: PHP/' . phpversion()."\r\n";
        $headers.= "BCC: $emailList";
    
    
        mail($to, $subject, $message, $headers);
    
    0 讨论(0)
提交回复
热议问题