0

I have a code to send html mail with php on cpanel but doesn't send without any errors. I have tested plain text mail and that is working fine, but once I add the header like below, it doesn't work.

//send html mail
ini_set('sendmail_from', 'info@toludimaokojie.com');
            $headers = "From: info@toludimaokojie.com\r\n"."X-Mailer: php";
            $headers .= "Content-type: text/html\r\n";
        $html = '<html> 
   <body>
  <h2>Result Analysis for Test With Reference Number:'.$reference.'</h2>
  <br/>
  <p><b>Personality: '.$personality_mail.'</b></p>
  <br/>
  <p><b>MBQ Score: '.$resultTotal.'</b></p>
  <br/>
  <ul>'.$analyseData.'</ul>
  <pre>Mail Sent on '.date("l, F Y H:i:sa").'</pre>
  </body>
  </html>';                          
  mail("olaegbesamuel@gmail.com", "MBQ TEST ANALYSIS", $html, $headers);

This doesn't work. Please help, i guess am doing everything correctly here. I have tested without html and confirmed that mail is working

goodhand
  • 189
  • 1
  • 1
  • 9

1 Answers1

0

You have defined $headers with all mandatory email parameters but look at your $header variable, there are two things need to be changed,

1) You have used $header and $headers both so use either of them and append them to one variable. 2) your 2nd line of $header variable is missing . to append the previous header values, so the corrected code should be:

         $headers = "From: info@toludimaokojie.com\r\n"."X-Mailer: php";
         $headers .= "From: $from\r\n"; 
         $headers .= "Content-type: text/html\r\n";

As you missed . operator in 2nd line, it will remove From header and so it would not be sending email. Try after changing these lines.

Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33