Click here to Skip to main content
15,888,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using phpmailer for sending emails, but I want to make a custom header for my compaign, by adding a textarea field that contain any custom header here is my code but i dont know where is the problem it not working i dont see my custom header in mail full header :

PHP
$headers = [];
                             foreach (preg_split('/[\r\n]+/', $_POST['customHeader']) as $line) {

                                 list($name, $value) = explode(': ', $line, 2);

                                   $headers[$name] = $value;
                             }

                           }
                           for ($hh=0; $hh < $headers.count; $hh++) {
                              $PHPMailer->addCustomHeader($name,$headers[$name]);
                           }


what can i do please , thanks in advance.

What I have tried:

i tried this code :
PHP
$headers = [];
                             foreach (preg_split('/[\r\n]+/', $_POST['customHeader']) as $line) {

                                 list($name, $value) = explode(': ', $line, 2);

                                   $headers[$name] = $value;
                             }

                           }
                           for ($hh=0; $hh < $headers.count; $hh++) {
                              $PHPMailer->addCustomHeader($name,$headers[$name]);
                           }
Posted
Updated 9-Jan-18 22:00pm
Comments
Peter_in_2780 1-May-16 23:11pm    
Your second loop is not using $hh, so it's not doing what it looks like. Why not just addCustomHeader($name, $value) right after explode() in the first loop?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900