Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Automated Emailing

We have a list of email addresses we want to send a fixed format email to.

The php program is in the attached file called email_batch.txt.

A sample of a small file of email addresses is attached in the file email_text.txt.

The script was run & the email was received by some (but not all) of the reciepients.

We are not clear that the script is working right.

Are there any problems with this script that would cause it to fail?
email-batch.txt
email-test.txt
Avatar of hielo
hielo
Flag of Wallis and Futuna image

>>A sample of a small file of email addresses is attached in the file email_text.txt
you don't have comma-separated list of email addresses. you have one email address per line. So try this :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
<head>
	<title>Test Emailing</title>
</head> 
<body>
<?php
$thefile = "data/email_batch.csv";
		$subj = "A Novel Holiday Gift Idea";
		$body = "<center>WHAT A NOVEL HOLIDAY GIFT!!</center><br><br>";
		$body = $body . "<b>Send a loved one a Personalized Holiday CD in which the receipient's name is sung 8 times</b> with loving wishes for the Holiday Season. It is sung to the same timeless tune as the ZOOM Birthday Song but with lyrics for the Holidays.It comes witha beautiful gift box for easy storage and with a special treat of a framed 4x6 photo of Captain Zoom and all his friends.Every name and spelling is available at no additional charge. This one of a kind gift will be loved by all and will be played over and over.<br><br>";	
		$body = $body . "You receive the Personalized Holiday Cd, the gift box, the 4x6 framed photo of Captain Zoom and his friends for $22.95 plus $6.95 for postage and handling and we will upgrade the shipping to priority mail to insure prompt trackable delivery. If you buy two or more cd's, ther will be no additional postage.\r\n<br><br>";		
		$body = $body . "As our Holiday gift to you, when you purchase 3 or more Personalized cd's whether for the Holiday Season or for a Birthday, THE 4TH ONE IS FREE!!! Please visit our website at  <a href='http://www.captainzoom.com'>www.captainzoom.com</a> in order to hear an excerpt of the songs and to place your order. For names not on the website or for other information, please call toll free 1-800 543 9112.<br>";		
		$header  = "MIME-Version: 1.0\r\n";
		$header .= "Content-type: text/html; charset=iso-8859-1\r\n";
		$header .= "From: noreply@captainzoom.com\r\n";	 
	$open = fopen($thefile, "r");
	if($open) {
		$data = file($thefile);
		foreach($data as $mailto){
			$mres = mail($mailto, $subj, $body, $header);	
?>
mail sent to = <? print $mailto; ?><br>
<?
		}
		fclose($open);
	}
	?>
		
</body>
</html> 

Other than that, it's possible the spam filters of the receipient's accounts are trashing the email.

Open in new window

You are attempting to use the mail function to send HTML formatted mail. To do this successfully you need to use something like the PEAR mail classes from www.pear.php.net

http://www.pear.php.net/package/Mail_Mime
http://www.pear.php.net/package/Mail

These would then be used as follows:
          $customerEmail  = "<html><head><title>$subject</title>".$this->styles."</head>";
          $customerEmail .= "<body>";
          if ( $subjHdr != "" )
               $customerEmail .= "<h3>$subjHdr</h3>";
          $customerEmail .= $mess . $attMess;
          $customerEmail .= "</body></html>";
 
          $mime->setHtmlBody($customerEmail);
          $body = $mime->get();
          $hdrs = $mime->headers($headers);
 
          $mail = &Mail::factory('mail');
 
          $result = ($mail->send($to, $hdrs, $body) == 1);

Open in new window

Avatar of Richard Korts

ASKER

To bportlock:

In the test file is my own email address. It sent it fine to me & I know 7 of the 10 names in the file received it too.

The email is formatted (html wise) correctly.

Whay is that?
To hielo:

In the test file is my own email address. It sent it fine to me & I know 7 of the 10 names in the file received it too.

I realize the file is not "truly" csv, but it seems to work at least MOST of the time.

Why is that?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial