Jump to content
  • Hello visitors, welcome to the Hacker World Forum!

    Red Team 1949  (formerly CHT Attack and Defense Team) In this rapidly changing Internet era, we maintain our original intention and create the best community to jointly exchange network technologies. You can obtain hacker attack and defense skills and knowledge in the forum, or you can join our Telegram communication group to discuss and communicate in real time. All kinds of advertisements are prohibited in the forum. Please register as a registered user to check our usage and privacy policy. Thank you for your cooperation.

    TheHackerWorld Official

Recommended Posts



  1. 使用php mail()发送邮件
  2. 使用第三方类库PHPMailer发送邮件


使用php mail()发送邮件

mail()是php的内置函数,它允许使用本地sendmail 程序发送电子邮件。无论何时调用mail()函数,它都会调用本地sendmail程序,该程序通常由系统管理员配置。如果你的虚拟主机位于Hostinger,你可以在电子邮件 - >邮件服务控制 部分启用/禁用此功能 。





to 必需。规定 email 接收者。
subject 必需。规定 email 的主题。注释:该参数不能包含任何新行字符。
message 必需。定义要发送的消息。应使用 LF (\n) 来分隔各行。

可选。规定附加的标题,比如 From、Cc 以及 Bcc。

应当使用 CRLF (\r\n) 分隔附加的标题。

parameters 可选。对邮件发送程序规定额外的参数。

使用php mail()发送html邮件


$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
<title>HTML email</title>
<p>This email contains HTML Tags!</p>

// 当发送 HTML 电子邮件时,请始终设置 content-type
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// 更多报头
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";



$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

使用php mail()发送纯文本邮件

$to = 'maryjane@email.com';
$subject = 'Marriage Proposal';
$message = 'Hi Jane, will you marry me?'; 
$from = 'peterparker@email.com';
// Sending email
if(mail($to, $subject, $message)){
    echo 'Your mail has been sent successfully.';
} else{
    echo 'Unable to send email. Please try again.';



PHPMailer是一个非常优秀的php第三方邮箱发送类函数, 专门用于php语言的邮件发送类,功能十分地强大,丰富了 PHP 本身单一的 mail() 函数。支持 SMTP 等、附件等。 PHPMailer 遵守 LGPL 授权,可以免费下载。


  1. 支持邮件 s/mime加密的数字签名
  2. 支持邮件多个 TOs, CCs, BCCs and REPLY-TOs
  3. 可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的
  4. 支持文本/HTML格式邮件
  5. 可以嵌入image图像
  6. 对于邮件客户端不支持HTML阅读的进行支持
  7. 功能强大的发送邮件调试功能debug
  8. 自定义邮件header
  9. 冗余SMTP服务器支持
  10. 支持8bit, base64, binary, and quoted-printable 编码
  11. 文字自动换行
  12. 支持多附件发送功能
  13. 支持SMTP服务器验证功能
  14. 在Sendmail, qmail, Postfix, Gmail, Imail, Exchange 等平台测试成功
  15. 提供的下载文件中,包括内容详细的说明文档及示例说明,所以不用担心难于上手的问题!
  16. PHPMailer 非常小巧、简单、方便、快捷




use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require_once "vendor/autoload.php";

//PHPMailer Object
$mail = new PHPMailer(true); //Argument true in constructor enables exceptions

//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("recepient1@example.com", "Recepient Name");
$mail->addAddress("recepient1@example.com"); //Recipient name is optional

//Address to which recipient will reply
$mail->addReplyTo("reply@yourdomain.com", "Reply");

//CC and BCC

//Send HTML or Plain Text email

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

try {
    echo "Message has been sent successfully";
} catch (Exception $e) {
    echo "Mailer Error: " . $mail->ErrorInfo;



require_once 'class.phpmailer.php';
$mail = new PHPMailer();
// Now you only need to add the necessary stuff
// HTML body
$body = "</pre>
$body .= " Hello Dimitrios
$body .= "<i>Your</i> personal photograph to this message.
$body .= "Sincerely,
$body .= "phpmailer test message ";
$body .= "</div>" ;
// And the absolute required configurations for sending HTML with attachement
$mail->AddAddress("sendemailto@mail.zz", "My-webpage Website");
$mail->Subject = "test for phpmailer-3";
if(!$mail->Send()) {
echo "There was an error sending the message";
echo "Message was sent successfully";


Link to post
Link to comment
Share on other sites


discussion group

discussion group

    You don't have permission to chat.
    • Recently Browsing   0 members

      • No registered users viewing this page.
    • Create New...