VernonDozier 2,218 Posting Expert Featured Poster

I'm having some problems using PHPMailer sending to gmail. I have plain-text and HTML e-mail contents. Mail is successfully received at an e-mail address in yahoo mail and an e-mail address in gmail. The problem is that the gmail e-mail shows up in plain text(all HTML formatting removed). The Yahoo e-mail shows up with the HTML formatting intact.

I'm wondering if there is some setting (mime type?) that I need to set to make it work in gmail and how to do it. Thanks. Code is below.

<?php
require("class.phpmailer.php");


$emailAddress = $_POST['emailAddress'];
$htmlFilename = $_POST['htmlFilename'];
$plainFilename = $_POST['plainFilename'];
$subject = $_POST['subject'];
$send_time = $_POST['send_time'];
$error = "";

if(empty($emailAddress))
{
    $error = "No POSTED emailAddress";
}
if(empty($htmlFilename))
{
    $error = "No POSTED htmlFilename";
}
if(empty($plainFilename))
{
    $error = "No POSTED plainFilename";
}
if(empty($subject))
{
    $error = "No POSTED subject";
}
if(empty($send_time))
{
    $error = "No POSTED send_time";
}


$handle = fopen("send_newsletter_log.txt", "a");

if(!$handle)
{
   die("could not open send_newsletter_log.txt for appending.");
}

if(!empty($error))
{
    fwrite($handle, $send_time);
    fwrite($handle, '\t');
    fwrite($handle, $emailAddress);
    fwrite($handle, '\t');
    fwrite($handle, 'Unsuccessful');
    fwrite($handle, '\t');
    fwrite($handle, $error);
    fwrite($handle, '\n');
    fclose($handle);
    die($error);
}


$mail = new PHPMailer();

// To load the English version
$mail->SetLanguage("en", "languageFiles");

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->Host = "mail.somedomainname.com";  // specify serer
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Port = 587;     //set outgoing SMTP port
$mail->Username = "bob@somedomainname.com";  // SMTP username
$mail->Password = "abcdef"; // SMTP password

$mail->From = "bob@somedomainname.com";
$mail->FromName = "Bob";
$mail->AddAddress($emailAddress);

$mail->WordWrap = 80;                                 // set word wrap to 80 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = $subject;
$mail->MsgHTML = file_get_contents ($htmlFilename);
$mail->AltBody = file_get_contents ($plainFilename);
$mail->Body    = file_get_contents ($htmlFilename);

if(!$mail->Send())
{
    fwrite($handle, $send_time);
    fwrite($handle, '\t');
    fwrite($handle, $emailAddress);
    fwrite($handle, '\t');
    fwrite($handle, 'Unsuccessful');
    fwrite($handle, '\t');
    fwrite($handle, $mail->ErrorInfo);
    fwrite($handle, '\n');
    fclose($handle);
    die($error);
}



fwrite($handle, $send_time);
fwrite($handle, '\t');
fwrite($handle, $emailAddress);
fwrite($handle, '\t');
fwrite($handle, 'Successful');
fwrite($handle, '\n');
fclose($handle);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.