Jump to content

[SOLVED] php mail sent but not always arrives


clintxp

Recommended Posts

I am trying to mass mail an email. The emails are sent successfully (no errors) but sometimes the email arrives and sometimes never arrives

 

my code is attached. I don't think there's something wrong with the code because sometimes it arrives. thanks for reading  :)

 

 

[attachment deleted by admin]

Each line should be separated with a LF (\n). Lines should not be larger than 70 characters

 

$message = "
<html>
</body>
  <span class=fs13>Dear $name<br><br>
  <img src=http://www.bitsandbytesmalta.com/mailinglist/picture.jpg border=0><br><br><br>
  <hr width=100% size=1><br>
  <span class=fs13><font face=tahoma><a href=http://www.bitsandbytesmalta.com/mailinglist/unsubscribe.php?email=$email>
   Please CLICK HERE if you wish to unsubscribe from our mailing list</a>
  <br><br>Your email address has not been given to any Third Parties.<br>
  The preceding is an email advertisement.";

$message = wordwrap($message, 70);

Sure, here it is:

 

			$SQL = "select * from `emails` where `email` like '[email protected]'";
		$retid = mysql_db_query($db, $SQL, $cid);
    
		if (!$retid) { echo( mysql_error()); }
		else {
        			while ($row = mysql_fetch_array($retid)) {
				$email = $row['email'];
				$name = $row['name'];
				$status = $row["status"];
				if (($name == "") or ($name == " ")) { $name = "Customer"; }

				$subject = "Special Offers from Bits & Bytes";

				$message = "
<html>
</body>
  <span class=fs13>Dear $name<br><br>
  <img src=http://www.bitsandbytesmalta.com/mailinglist/picture.jpg border=0><br><br><br>
  <hr width=100% size=1><br>
  <span class=fs13><font face=tahoma><a href=http://www.bitsandbytesmalta.com/mailinglist/unsubscribe.php?email=$email>
   Please CLICK HERE if you wish to unsubscribe from our mailing list</a>
  <br><br>Your email address has not been given to any Third Parties.<br>
  The preceding is an email advertisement.

				";
$message = wordwrap($message, 70);

				$headers = 'From: Bits & Bytes Malta <[email protected]>' . "\r\n";
				$headers .= 'MIME-Version: 1.0' . "\r\n";
				$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

				if (mail($email, $subject, $message, $headers)) {
					echo ("<center><span class=fs13><font face=tahoma color=black><br>$email</span></center>");
				}
				else {
					echo ("<center><span class=fs13><font face=tahoma color=red><br>$email</span></center>");
				}
			}
		}

 

thanks

I would do it like this.

 

First you pull the emails into an array, and add an other field in ur table that shows what users want to recieve email if u dont have that yet

e.g. 'sendMeNewsletter' which can have values 0 = dont send me newsletter or 1 = send me newsletter. You can name that field whatever u want.

 


// this pulls email addresses into an array
$sql = mysql_query("SELECT * FROM emails WHERE sendMeNewsletter ='1') or die('Error, query failed. ' . mysql_error()); 
while($row = mysql_fetch_array($sql)) {
$email[] = $row['email'];
}
// end email array

 

then you will send the email to those who want it

 


foreach($email as $key => $value) {

$result = mysql_query("SELECT email, name FROM emails WHERE email = '$value'") or die('Error, query failed. ' . mysql_error());
list($email, $name) = @mysql_fetch_array($result);

// headers
$subject = "Special Offers from Bits & Bytes";
$no_reply = ' "Bits & Bytes Malta" <[email protected]>';

$header = "Return-Path: $no_reply>\r\n"; 
$header .= "From: $no_reply\r\n"; 
$header .= "Content-Type: text/html; charset=iso-8859-1;\n\n\r\n";

// here you put ur email body and use html attachments and so on. Make sure to escape html attributes like <table width=\"70%\"></table>
$body = "Hi $name<br /></br />"; // or u can call it $message. ur choice. I would call it body
$body .="some text and html whatever images etc";
$body .="some text and html whatever images etc";
$body .="some text and html whatever images etc";
$body .="some text and html whatever images etc";
$body .="some text and html whatever images etc";
$body .="some text and html whatever images etc";
// end email body

mail($value, $subject, $body, $header); 
} // end send email

 

and you are done. Try this one. Hope it works for u :) Make sure u set the timeout longer in case u have like thousands of subscribers, otherwise u need to divide the emails in smaller ammounts.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.