doxn43207 2012-07-04 14:01
浏览 36

GMAIL在发送SMTP邮件时显示BCC列表

I had an issue with gmail where it was displaying the recipients sent to a BCC list. The solution to this was to not include the BCC list in the headers but instead append it to the list of recipients in the PEAR moodule

See this link - http://rawphp.com/php_generator/page.php?show=PHP_Sending_Email_to_Bcc_with_SMTP_Authentication_pear_mail_factory.php

So I've posted this to anyone else who needs to know this.

<?php function sendSmtpEmail($listType = 'To', $recipientList,$from,$subject = NULL,$message = NULL){

    require_once "Mail.php";

    /*$recipients = "Recipient <email@email.co.uk>";
    $from = "An Email <email@email.co.uk>";
    $subject = 'testing relay';
    $message = "<hteml><head></head><body><h1>This is a test</h1>";
    $message .= "<p>Paragraph</p>";
    $message .= "<ul><li>list item 1</li><li>List item 2</li></body>";*/

    $host = ini_get("SMTP");
    $username = NULL;
    $password = NULL;

    $headers['From'] = $from;

    ///// Set to send as won't send without a to address
    /*if($listType != 'To'){                
        $headers[$listType] = $recipientList;
        $headers['To'] = $from;
    } else { //// Is a to address*/
        $headers['To'] = '';
    /*}*/

    $recipients = $recipientList;

    $headers['Subject'] = $subject;
    $headers['host'] = $host;
    $headers['MIME-Version'] = '1.0';
    $headers['Content-type'] = 'text/html; charset=iso-8859-1';
    $params['sendmail_path'] = '/usr/lib/sendmail';

    // Create the mail object using the Mail::factory method
    $mail_object =& Mail::factory('sendmail', $params);

    $mail_object->send($recipients, $headers, $message);    

    if (PEAR::isError($mail_object)) {
        echo("<p>" . $mail_object->getMessage() . "</p>");
    } else {
        echo "<p>Mail sent succefully</p>"; echo $from; echo $recipientList; die();
    }



}
?>

Thanks

Andi

  • 写回答

1条回答 默认 最新

  • donglun7151 2012-07-04 14:01
    关注

    Please See as above. I have tidied up the function

    <?php
    
    function sendSmtpEmail($recipientList,$from,$subject = NULL,$message = NULL){
    
        require_once "Mail.php";
    
        $host = ini_get("SMTP");
        $username = NULL;
        $password = NULL;
    
        $headers['From'] = $from;       
        $headers['To'] = '';
    
        $headers['Subject'] = $subject;
        $headers['host'] = $host;
        $headers['MIME-Version'] = '1.0';
        $headers['Content-type'] = 'text/html; charset=iso-8859-1';
        $params['sendmail_path'] = '/usr/lib/sendmail';
    
        // Create the mail object using the Mail::factory method
        $mail_object =& Mail::factory('sendmail', $params);
    
        $mail_object->send($recipientList, $headers, $message); 
    
        if (PEAR::isError($mail_object)) {
            echo("<p>" . $mail_object->getMessage() . "</p>");
        } else {
            echo "<p>Mail sent succefully</p>";
        }           
    }
    ?>
    

    Hope this helps anyone.

    Thanks

    Andi

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号