Proper prevention of mail injection in PHP

后端 未结 4 1791
小鲜肉
小鲜肉 2020-11-28 15:17

Could you advise me how do I go about preventing email injection in PHP mail() without losing original message data? E.g. if I need to allow user to use \

4条回答
  •  死守一世寂寞
    2020-11-28 15:48

    Use a designated mime email library, like Mail_Mime:

    setTXTBody("Message goes here");
    $hdrs = $mime->headers(array(
        'From'    => 'you@yourdomain.com',
        'Subject' => 'Test mime message'
    ));
    $body = $mime->get();
    
    $mail = &Mail::factory('mail');
    $mail->send('postmaster@localhost', $hdrs, $body);
    
    ?>
    

提交回复
热议问题