如何使用phpmailer设置自定义标头

dra*_*vos 12 email header phpmailer return-path

我使用phpmailer发送电子邮件,但我想为我的公司制作一个自定义标题,通过添加包含任何自定义标题的textarea字段,例如使用像这样的标题:

标题 或任何其他标题类型的例子..我怎么能这样做,提前谢谢.

Hen*_*alg 22

您将需要对PHPmailer设置的默认标头进行一些发现和修改,以实现此目的.

您需要使用不同的功能来设置/编辑标题,具体取决于您要设置/编辑的标题类型.这里有一些例子:

从:

$mail->setFrom('from@example.com', 'Mailer');
Run Code Online (Sandbox Code Playgroud)

学科:

$mail->Subject = 'Here is the subject';
Run Code Online (Sandbox Code Playgroud)

自定义:

$mail->addCustomHeader('X-custom-header', 'custom-value');
Run Code Online (Sandbox Code Playgroud)

简而言之,当标题在文本框中自由输入时,这是非常努力的.但是,您可以通过检测和验证进行操作.

  • 如果你想做更少的解析,你可以将名称和值一起发送,比如`$ mail-> addCustomHeader('X-custom-header:custom-value');`https://github.com/PHPMailer/ PHPMailer的/斑点/主/ class.phpmailer.php (2认同)