views:

38

answers:

2

I have various emails being sent out via PHP mail. The problem is, for example when I receive the email, it is displayed in the body properly without any surrounding html. For some reason, other people that I am testing it out with are getting it with the html showing up.

Here is an example of one of the emails being sent:

        $Email = $result['Email'];
        $check_profi = $result['check_profi'];
        $check_reply = $result['check_reply'];

        if($prof->id != $auth->id && $check_profi == 'checked') {

        $to = $Email;
        $subject = "$auth->first_name $auth->last_name left you a comment on Blah.com";
        $message = "$auth->first_name $auth->last_name left you a comment on Blah.com: <br /><br />\"$body\"<br /><br /> <a href='http://www.Blah.com.php?id=" . $prof->id . "'>Click here to view</a><br /><br />Do LIFE,<br />";
        $from = "Blah <[email protected]>";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= "From: $from";
        mail($to, $subject, $message, $headers);
    }

I have been suggested PHP mailer but that is a huge way around something simple I need to do. I already have my mail all set up and it works great,except this small issue.

A: 

Those who see the HTML probably don't have readers supporting HTML email. Trying including a plaintext alternative.

Chuck
+1  A: 

Perhaps you're forgetting some necesary headers. Normally I use an specific mail library to avoid these issues, like PHPMailer ( http://sourceforge.net/projects/phpmailer/ )

Angel Aparicio
Is there a way to add this on to what I already have? This is new to me so I am not exactly sure how to implement it. Thanks!
LightningWrist
Download PHPMailer from http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/PHPMailer_v5.1.zip/download and get the class.*.php filesThen you have to code something like this :require("class.phpmailer.php");$mail = new PHPMailer();$mail->From = '[email protected]';$mail->FromName = 'Blah';$mail->Body = "The message in HTML";$mail->Subject = "The subject";$mail->AddAddress($Email);$mail->IsHTML(True);$mail->Send();This should work
Angel Aparicio