-2

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:

Subject: __Subject
From: __From
Reply-to: <__Reply-To> 
To: __To
Date: __smtpDate

or any other header types.. How can I do this in details please, thanks in advance.

KittMedia
  • 7,368
  • 13
  • 34
  • 38
dravos
  • 313
  • 1
  • 3
  • 9
  • post your code it will be easy to recognize your question – Willie Cheng May 01 '16 at 07:20
  • 1
    Possible duplicate of [How to set a custom header using phpmailer](http://stackoverflow.com/questions/36927416/how-to-set-a-custom-header-using-phpmailer) – Synchro May 01 '16 at 07:50

2 Answers2

0

Use the addCustomHeader() method

Provides ability for user to create own custom headers (like X-Priority, for example).

Example use:

$mail->addCustomHeader("X-Priority: 3"); 

SRC: http://phpmailer.github.io/PHPMailer/classes/PHPMailer.html#method_addCustomHeader

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • please give me an exemple for this header : Subject: __Subject From: __From Reply-to: <__Reply-To> To: __To Date: __smtpDate – dravos May 01 '16 at 07:16
  • Why are you pointing links back to obsolete resources after I've corrected them? As the package maintainer I have to fight against this tide of crap every day. – Synchro May 01 '16 at 07:53
0

To parse the fields into an array (assuming your textarea is called mytextarea):

$headers = [];
foreach (preg_split('/[\r\n]+/', $_POST['mytextarea']) as $line) {
    list($name, $value) = explode(': ', $line, 2);
    $headers[$name] = $value;
}

var_dump($headers);

Then you can iterate over that array and process each header. Most of the headers you have listed require special handling, for example Subject should be put into $mail->Subject, not used with addCustomHeader. All that is covered in the PHPMailer docs and examples, so there is no point in expanding that here.

Synchro
  • 35,538
  • 15
  • 81
  • 104