首页 文章

发出PHP邮件 Headers

提问于
浏览
2

我在使用php邮件时遇到以下问题,我将公开我做的两种方式,结果我得到并期待:

情况1:

$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

我发送的电子邮件和html以正确的方式解码,但我的“From” Headers 看起来像:“noreply@124512.net”(奇怪的根) .

案例2:

$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply@example.com\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

现在我的“From” Headers 很好,“noreply @ example.com”,但邮件不解码html,所以我无法以正确的方式查看邮件 .

2 回答

  • 0

    尝试将MIME版本添加到标头中:

    $headers .= "MIME-Version: 1.0\n";
    

    对于无回复,我建议你使用 Reply-To 添加它:

    $headers .= "Reply-To: noreply@example.com\n";
    

    这样您就可以更好地保留电子邮件地址 . 在我的代码中,我在每个 Headers 行使用 \nfinish 使用 \r\n .

  • 2

    来自:http://de3.php.net/manual/en/function.mail.php

    示例#4发送HTML电子邮件

    也可以使用mail()发送HTML电子邮件 .

    <?php
    // multiple recipients
    $to  = 'aidan@example.com' . ', '; // note the comma
    $to .= 'wez@example.com';
    
    // subject
    $subject = 'Birthday Reminders for August';
    
    // message
    $message = '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
    </head>
    <body>
      <p>Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
        </tr>
        <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
        </tr>
      </table>
    </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: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
    $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
    $headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
    $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
    
    // Mail it
    mail($to, $subject, $message, $headers);
    ?>
    

相关问题