17

I am using phpmailer for sending emails, but I want to make a custom header for my company, by adding a textarea field that contain any custom header for example using a header like this one:

exemple of header or any other header types.. How can I do this , thanks in advance.

Henkealg
  • 1,466
  • 1
  • 16
  • 19
dravos
  • 313
  • 1
  • 3
  • 9
  • It's up to you to write a parser for fields like that, but once you've done that, PHPMailer will be happy to add them as real custom headers using the `addCustomHeader() `function. What have you tried so far? – Synchro Apr 29 '16 at 00:08
  • i need more explanation please , pratical exemple if you can :) – dravos Apr 29 '16 at 13:03

1 Answers1

33

You will need to do some discovery and modification of the default headers set by PHPmailer for this to be achieved.

You will need to use different functions to set/edit headers depending on the type of header you want to set/edit. Here are a few examples:

From:

$mail->setFrom('from@example.com', 'Mailer');

Subject:

$mail->Subject = 'Here is the subject';

Custom:

$mail->addCustomHeader('X-custom-header', 'custom-value');

In short, It is quite an effort to do this when the headers are free-typed in a text box. It is however doable with detection and validation on your side.

Henkealg
  • 1,466
  • 1
  • 16
  • 19
  • thank you for you quick response , but if you can give me a pratical exemple for this picture http://i.stack.imgur.com/4afxd.jpg – dravos Apr 29 '16 at 13:04
  • 1
    You're offering security training and you don't know what parsing means? Sounds a bit spammy to me. – Synchro Apr 29 '16 at 15:32
  • i know what parsing means , but it a bit difficult in this case – dravos Apr 29 '16 at 18:28
  • 1
    If you think this is difficult, you *really* don't know what parsing means. – Synchro May 01 '16 at 07:51
  • 2
    If you want to do even less parsing, you can send the name and value together, like `$mail->addCustomHeader('X-custom-header: custom-value');` https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php – Autumn Leonard Feb 03 '17 at 16:44