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]

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

Sure, here it is:

 

			$SQL = "select * from `emails` where `email` like 'clintxp@gmail.com'";
		$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 <mailinglist@bitsandbytesmalta.com>' . "\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

Link to comment
Share on other sites

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" <mailinglist@bitsandbytesmalta.com>';

$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.

Link to comment
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.