Change from PHPmailer to sendmail

☆樱花仙子☆ 提交于 2021-02-08 10:25:21

问题


I want to send the emails via original old school sendmail.

In what way i need to change this CODE to work with sendmail?

i have tried but i always get very ugly errors, i tried to change IsMail to IsSedmail but still does not send the original way.

Phpmailer sends 3 email and the website is taking a lot time to send, so i want to go to the old plain "mail(to...." but the problem is that i`m lost in all the code so please Help.

function send_mail($rec_email,$subject,$message, $IsHtml=false, $cc=array(), $bcc=array()) {
    global $THIS_BASEPATH, $btit_settings;

    if (!method_exists('PHPMailer','IsMail'))
        include($THIS_BASEPATH.'/phpmailer/class.phpmailer.php');
    $mail=new PHPMailer();

    if ($btit_settings['mail_type']=='php') {
        $mail->IsMail();                                   # send via mail
        if (!empty($cc))
            $mail->AddCustomHeader('Cc: '.implode(',',$cc));
        if (!empty($bcc))
            $mail->AddCustomHeader('Bcc: '.implode(',',$bcc));
    } else {
        $mail->IsSMTP();                                   # send via SMTP
        $mail->Host     = $btit_settings['smtp_server'];   # SMTP servers
        $mail->Port     = $btit_settings['smtp_port'];     # SMTP port
        $mail->SMTPAuth = true;                            # turn on SMTP authentication
        $mail->Username = $btit_settings['smtp_username']; # SMTP username
        $mail->Password = $btit_settings['smtp_password']; # SMTP password
        if (!empty($cc))
            foreach($cc as $carbon_copy)
                $mail->AddCC($carbon_copy[0],$carbon_copy[0]);

        if (!empty($bcc))
            foreach($bcc as $blind_carbon_copy)
                $mail->AddBCC($blind_carbon_copy[0],$blind_carbon_copy[0]);
    }

    $mail->From     = $btit_settings['email'];
    $mail->FromName = $btit_settings['name'];
    $mail->CharSet  = $btit_settings['default_charset'];
    $mail->IsHTML($IsHtml);
    $mail->AddAddress($rec_email);
    $mail->AddReplyTo($btit_settings['email'],$btit_settings['name']);
    $mail->Subject  =  $subject;
    $mail->Body     =  $message;

    return ($mail->Send())?true:$mail->ErrorInfo;
}

Thank You very much.


回答1:


PHPmailer is not the culrpit for "slowness", it's probably the SMTP server you've specified. Do not stop using PHPmailer, though. PHPmailer does tons of extra stuff behind the scenes to send mail correctly.

To send mail out through the local server using PHP's mail() replace:

$mail->IsSMTP();                                   # send via SMTP
$mail->Host     = $btit_settings['smtp_server'];   # SMTP servers
$mail->Port     = $btit_settings['smtp_port'];     # SMTP port
$mail->SMTPAuth = true;                            # turn on SMTP authentication
$mail->Username = $btit_settings['smtp_username']; # SMTP username
$mail->Password = $btit_settings['smtp_password']; # SMTP password

With:

$mail->isMail();

That's it.

If you are certain that the server has either Sendmail [or a drop-in replacement like Postfix or Exim] installed then you can use:

$mail->isSendmail();

However, by using the web server to send out mail you are now dependent on:

  1. The installed MTA being configured correctly, which they frequently aren't.
  2. The reputation of the web server according to various blacklists. Generally, web servers have s**t reputations because anyone can drop outbound mail into the queue without authentication.


来源:https://stackoverflow.com/questions/22078790/change-from-phpmailer-to-sendmail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!