Jump to content

Recommended Posts

I'm not a PHP guy - someone else wrote my code.

 

I have a php script that steps through a mySQL database to pull email addresses and reads a text file which it sends as an email.  It work fine.  Here is the relevant code:

 

//READ THE FILE INTO MEMORY AND FORMAT THE EMAIL TEXT
    
$filename = "/home/scamout/public_html/test.txt";
$fp = fopen($filename, "r");
// $EMailText = "Hello,";
$EMailText .= "\n\n";
$EMailText .= (fread($fp, 60000));
fclose($fp);

//END FILE READ


// PERFORM SQL QUERY TO GET ALL ACTIVE MEMBERS
$query = "SELECT MemberEmail FROM members where DateAdded < 2004-06-01 21:00:00 and Status > 3"; 

$result = mysql_query($query)
   			 or die( mysql_error($DB_link) );
while ( $line = mysql_fetch_array($result) )

{
$emailaddr = $line["MemberEmail"]; 
$FromId = "Merchant911 Admin <admin@merchant911.org>";
$EMailSubject = "[MERCHANT 911] Important Mail from Merchant911";

$headers = array ('From' => $FromId,'To' => $emailaddr,'Subject' => $EMailSubject) ;


$sendit = Mail::factory('smtp',array ('host' => "mail.merchant911.org",'auth' => true,'username' => "myusername",'password' => "mypasswords"));
$mail = $sendit->send($emailaddr, $headers, $EMailText);

 

Now I need to send out html email.  After much Google searching and lots of trial and error, I amended  the $headers portion to this:

 

$headers = array ('From' => $FromId,'To' => $emailaddr,'Subject' => $EMailSubject) ;
$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

I'm not getting errors in that portion of the code (finally) but now I'm getting:

  • Warning: Invalid argument supplied for foreach() in /usr/local/lib/php/Mail.php on line 123
     
    Warning: Invalid argument supplied for foreach() in /usr/local/lib/php/Mail.php on line 151
    The all member mailing completed.
     

 

On a shared server, I don't have access to Mail.php so I can't go further.

 

Can someone help?

Link to comment
https://forums.phpfreaks.com/topic/191113-sending-html-formated-email-with-php/
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.