Jump to content

Problem with headers in mail function (html format)


Raz3rt

Recommended Posts

I have a strange problem with my headers in my mail function.

This is how it looks like in my code:

$to              = 'someone@email.com';
$subject         = 'Question from website';
$headers         = 'MIME-Version: 1.0' . "\r\n";
$headers        .= 'Content-type: text/html;charset=UTF-8' . "\r\n";
$headers        .= 'From: ' . $email . "\r\n";

When i send this i got the following message in my mailbox:

Content-type: text/html;charset=UTF-8

From: web@somecompany.com
Message-Id: <20140620142808.93D11A147@apache11.hostbasket.com>
Date: Fri, 20 Jun 2014 16:28:08 +0200 (CEST)

<html><head><title>Question from web</title><style type="text/css">body {background-color: #ffffff; font-family: verdana;}hr {color: #333;}div {width: 800px; margin: 25px auto;}h1 {color: #FFC421; font-size: 17px;}p {color: 2a2a2a; font-size: 15px;}</style></head><body><div><p><img src="imgs/tsc-logo.png"/></p><hr /><h2 style="color: #FFC421;">This customer asked a question</h2><br /><table style="width:800px"><tr><th style="width:250px"><h1>Customer:</h1></th><td></td></tr><tr><th>Name:</th><td>testname</td></tr><tr><th>Firstname:</th><td>testfirstname</td></tr><tr><th>E-mail:</th><td>testperson@company.be</td></tr><tr><th>Bericht:</th><td>This is a test</td></tr></table></div></body></html>

I have allready found that the space between "Content-type" and "From" is not normal that indicates that a rule between MIME and Content-type is also present. But in my code there isn't any rule... How can this be possible?

 

Thanks for the help!

Link to comment
Share on other sites

Hi Raz3rt

 
Nothing jumps out at me, though 4am...
 
Could you please show us the full mail code.
 
This is what I use in my headers:
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Take over the world Reminder <totw@example.com>' . "\r\n";

Worth trying a different header. Are you also sure the SMTP/POP3 server is setup correctly?

Edited by Ansego
Link to comment
Share on other sites

Hello,

 

thank you for the answers. Here is my full code copy pasted fram my project (it's in Dutch language, sorry for that!)

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    if (!empty($_POST['email'])) {
        
    $name           = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
    $firstname      = filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING);
    $email          = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    $info           = filter_input(INPUT_POST, 'info', FILTER_SANITIZE_STRING);
    
    $message     = '<html><head>';
    $message    .= '<title>Vraag vanaf de website</title>';
    $message    .= '<style type="text/css">body {background-color: #ffffff; font-family: verdana;}hr {color: #333;}div {width: 800px; margin: 25px auto;}h1 {color: #FFC421; font-size: 17px;}p {color: 2a2a2a; font-size: 15px;}</style>';
    $message    .= '</head>';                  
    $message    .= '<body>';            
    $message    .= '<div>';        
    $message    .= '<p><img src="imgs/tsc-logo.png"/></p>';        
    $message    .= '<hr />';                
    $message    .= '<h2 style="color: #FFC421;">Klant heeft een vraag gesteld via de website</h2>';                        
    $message    .= '<br />';                  
    $message    .= '<table style="width:800px">';              
    $message    .= '<tr><th style="width:250px"><h1>Gegevens klant:</h1></th><td></td></tr>';            
    $message    .= '<tr><th>Naam:</th><td>' . $name . '</td></tr>';         
    $message    .= '<tr><th>Voornaam:</th><td>' . $firstname . '</td></tr>';                       
    $message    .= '<tr><th>E-mail:</th><td>' . $email . '</td></tr>';                       
    $message    .= '<tr><th>Bericht:</th><td>' . $info . '</td></tr>';                       
    $message    .= '</table>';                       
    $message    .= '</div>';                
    $message    .= '</body></html>';                               
    
$to         = 'someone@telenet.be';
$subject    = 'Vraag vanop de website';
$headers    = 'MIME-Version: 1.0' . "\r\n";
$headers    .= 'Content-type: text/html;charset=UTF-8' . "\r\n";
$headers    .= 'From: ' . $email . "\r\n";
    
    if (mail($to, $subject, $message, $headers)){
            $_SESSION['email'] = $email;
            header ('Location: index.php?pagina=send');
        } else {
            header ('Location: index.php?pagina=404');
        }
}

}

Could it be a problem with the host where the website is hosted?

Edited by Raz3rt
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.