代码之家  ›  专栏  ›  技术社区  ›  RonLugge

显示名称而不是电子邮件的电子邮件头的格式是什么?

  •  44
  • RonLugge  · 技术社区  · 14 年前

    我正在尝试创建一个php脚本,它将使用mySQL数据库为我处理邮件列表,我已经准备好了大部分。不幸的是,我似乎无法使标题正常工作,我不知道是什么问题。

    $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";
    

    我在接收端得到的结果是:

    “不公平”@rilburskryler.net网站答复:邮箱:noreply@rilburskryler.netrnX-Mailer:PHP/5.2.13rnMIME-Version:1.0

    3 回复  |  直到 14 年前
        1
  •  122
  •   Luke Stevenson    8 年前

    "John Smith" <johnsemail@hisserver.com>
    

    容易的。

    $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 );
    
        2
  •  11
  •   Gumbo    14 年前

    在一个 single quoted string ,只有转义序列 \' \\ ' \ 分别。你需要使用 double quotes \r \n 替换为相应字符:

    $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";
    

    您还可以使用数组收集标题字段,然后将它们放在一起:

    $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);
    
        3
  •  -2
  •   cmptrwhz    14 年前
        $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);