Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php Mail() and Outlook

Tags:

php

email

outlook

I have the following code:

    $subject = "Test Email";
    $from = "[email protected]";
    ini_set("sendmail_from", $from);
$message = "<html><body bgcolor=\"#DCEEFC\"> 
                Hello<br><br>
                This is a <b>test</b> email.
                <br><br><hr>
                <a href=\"\">Click Here</a>     
                <br><br><hr>
                <br><br>
                Thank you for your time,<br><br>
            </body></html>";

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html\r\n"; 
    $headers .= "From: " . $from . "\r\n";
    mail($mail, $subject, $message, $headers);

However, when I send the email to myself, I see all the code in Outlook. If i send it to someone else, They see the HTML. If i send it to my hotmail, they see the HTML.

Is this a problem with my outlook (2007), if so, what is it, or can I do something in the email to guarantee it being displayed properly?

Please help!

like image 293
Chud37 Avatar asked Aug 01 '12 11:08

Chud37


People also ask

How to send emails in PHP?

Copied! Copied! If your website or web application is built on PHP, you can utilize the PHP mail feature to send emails. It can come in handy for creating custom-built mail forms and sending simple text-based email messages.

What is PHPMailer and how to use it?

PHPMailer is a popular mail sending library for PHP. It supports mail sending via mail() function or Simple Mail Transfer Protocol . This library simplifies the complicated process of building a PHP mail by providing a set of functions to create and send an email. Installing PHPMailer is quite simple, especially if you have Composer installed.

What's new in PHP for email delivery?

Note: Keep in mind that even if the email was accepted for delivery, it does NOT mean the email is actually sent and received! PHP 5.4: Added header injection protection for the headers parameter. PHP 4.3.0: (Windows only) All custom headers (like From, Cc, Bcc and Date) are supported, and are not case-sensitive.

What is the use of mail () function in PHP?

The mail() function in PHP allows sending email using a local sendmail program. Whenever you call the mail() function, it invokes a local sendmail program, usually configured by the system administrator.


2 Answers

Try to reorder the header. I remember having the same problem a while ago and it worked after I used the following headers:

    $headers = "From: " .$from. "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
    $headers .= "Content-Transfer-Encoding: 8bit\r\n";

I would recommend though to use a ready-to-go php mailer class - it makes life much easier.

like image 42
MiDo Avatar answered Sep 19 '22 09:09

MiDo


I found the problem:

HTML Email not displaying correctly for Godaddy web based mail

Changed:

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n"; 
$headers .= "From: " . $from . "\r\n";

to:

$headers  = "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-Type: text/html; charset=ISO-8859-1" . PHP_EOL;
$headers .= "From: Site<$from>" . PHP_EOL;

Thanks for all your help guys! :)

like image 143
Chud37 Avatar answered Sep 21 '22 09:09

Chud37