首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Php $headers中断功能

Php $headers中断功能
EN

Stack Overflow用户
提问于 2013-11-25 06:59:51
回答 4查看 358关注 0票数 0

我有一个功能,发送多个电子邮件出去,取决于多少产品是购买在oscommerce。在我为函数的php mail()部分添加标题之前,它工作得很好。如您所见,我的标题如下:

代码语言:javascript
复制
    $headers .= 'MIME-Version: 1.0' . "\r\n";  
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

    $headers .= "From: info@email.com \r\n" .  
           "Reply-To: info@email.com \r\n" .  
           "X-Mailer: PHP/" . phpversion();

但是当我声明标题(为了将电子邮件发送为html)时,只发送第一封电子邮件。我可以不多次发送标头吗?如有任何建议,将不胜感激!

函数片段:

代码语言:javascript
复制
foreach ($dstToProduct as $dsid => $productIndices) {
    $email = $newDropships[$dsid]['email'];
    $subject = "A new order has been placed";
    $headers .= 'MIME-Version: 1.0' . "\r\n";  
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

    $headers .= "From: info@email.com \r\n" .  
           "Reply-To: info@email.com \r\n" .  
           "X-Mailer: PHP/" . phpversion();




    // Build message text
    $date = date('m/d/Y');

    $text = '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';

    foreach ($productIndices as $productIndex) {

            $text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';

    }

        $text .= '</table>';


    if (!mail($email, $subject, $text, $headers)) {
        mail('info@email.com', 'Error sending product', 'The following order was not sent:&nbsp;' . $order_id);
    }

}
}
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-11-25 07:50:13

试试这个:

代码语言:javascript
复制
$subject = "A new order has been placed";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
$headers .= 'From: Info <info@email.com>' . "\r\n";
$headers .= 'Reply-To: Info <info@email.com>' . "\r\n";
$headers .=  "X-Mailer: PHP/".phpversion();   
$date = date('m/d/Y');
foreach ($dstToProduct as $dsid => $productIndices) 
{
 $email = $newDropships[$dsid]['email'];
 $text = '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';

  foreach ($productIndices as $productIndex) {

  $text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';

  }
 $text .= '</table>';
 if (!mail($email, $subject, $text, $headers)) {
    mail('info@email.com', 'Error sending product', 'The following order was not sent:&nbsp;' . $order_id);
}

}

票数 2
EN

Stack Overflow用户

发布于 2013-11-25 07:40:54

你可以试试像这样的

希望它对你有用..。

代码语言:javascript
复制
 <?php
    $headers=array(
        'MIME-Version: 1.0' . "\r\n",
        'From: info@email.com',
        'Content-Type:text/html',
        'Reply-To: info@email.com'
    );
    $subject = "A new order has been placed";

    foreach ($dstToProduct as $dsid => $productIndices) {
        $email = $newDropships[$dsid]['email'];


    // Build message text
        $date = date('m/d/Y');

        $text = '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';

        foreach ($productIndices as $productIndex) {

        $text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';

        }

        $text .= '</table>';   
        $body = $text;


    if (!mail($email,$subject,$body,implode("\r\n",$headers))) {
            mail('info@email.com', 'Error sending product', 'The following order was not sent:&nbsp;' . $order_id);
        }


    }
票数 1
EN

Stack Overflow用户

发布于 2013-11-25 07:49:13

如果您认为phpversion()会引发问题,请尝试如下所示:

代码语言:javascript
复制
    $phpV =  phpversion();
    $subject = "A new order has been placed";
    $headers .= 'MIME-Version: 1.0' . "\r\n";  
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
    $headers .= "From: info@email.com \r\n" .  
                "Reply-To: info@email.com \r\n" .  
                "X-Mailer: PHP/" .$phpV; 

通常,您不需要每次都这样做,而不是特定用户的变量取决于--您可以声明一次。就像这样:

代码语言:javascript
复制
$subject = "A new order has been placed";
$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

$headers .= "From: info@email.com \r\n" .  
       "Reply-To: info@email.com \r\n" .  
       "X-Mailer: PHP/" . phpversion();

$date = date('m/d/Y');

$text = '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';
foreach ($productIndices as $productIndex) {
    $text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' 
    . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">'
    . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' 
    . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">'
    . $products_array[$productIndex]["price"] . '</td></tr>';
}
$text .= '</table>';

foreach ($dstToProduct as $dsid => $productIndices) {
    $email = $newDropships[$dsid]['email'];
    if (!mail($email, $subject, $text, $headers)) {
        mail('info@email.com', 'Error sending product', 'The following order was not sent: ' . $order_id);
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20186428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档