I want to send an email and I am using the code below. It always works on my test server and my production server which are both IIS on Windows. It sometimes works the client's server. Once or twice in ten it sends. The client's server is running Apache on Linux. Could this be significant? Any other ideas why it would only work intermitently?

I have included everything except input validation (way too much code - not needed for testing) and the three images. If anyone is kind enough to test this for me then the images can be found here:

http://www.slymedesign.co.uk/images/top.png
http://www.slymedesign.co.uk/images/welcome-top.jpg
http://www.slymedesign.co.uk/images/welcome-bottom.jpg

Although, to be honest, I don't think that the email is the problem. I get similar results if I strip the email message right down to simple 'Hello World' stuff.

<?php

$ready_to_send = false;
$send_status = '';

if (isset($_POST['submit'])) {
	$to = $_POST['email'];
	$ready_to_send = true;
}

if ($ready_to_send) {
	$top_png = chunk_split(base64_encode(file_get_contents('top.png')));
	$welcome_top_jpg = chunk_split(base64_encode(file_get_contents('welcome-top.jpg')));
	$welcome_bottom_jpg = chunk_split(base64_encode(file_get_contents('welcome-bottom.jpg')));
	$subject = 'Multipart Email Test'; 
	$headers = "From: $to\r\nReply-To: $to"; 
	$headers .= "\r\nContent-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=_NextPart_000_0070_01CAFD85.CD836AE0\""; 
	ob_start();
?>
This is a multi-part message in MIME format.

------=_NextPart_000_0070_01CAFD85.CD836AE0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0071_01CAFD85.CD836AE0"


------=_NextPart_001_0071_01CAFD85.CD836AE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

      Great! You have successfully registered as a curbappeal user....

      You are now in the privileged position of receiving updates on the new stylish venues to try out around the globe. As a registered member you are also entitled to receive offers negotiated especially for you.
     

     
      Say goodbye to the endless hours of surfing the web trying to find cool restaurants, cafes,
      bars, hotels, spas....just 'curbappeal it'
     

     
      Don't forget, as this is a new website, there will be frequent uploads of more exciting venues for you to check out...so keep logging on to www.thisiscurbappeal.com for new ideas.

      If there are any venues you think should make it onto our site, then please contact us on info@thisiscurbappeal.com
     

--------------------------------------------------------------------------

      curbappeal: noun
      1. The visual attractiveness of a property as seen from the street
      2. A Property that looks architecturally distinctive and well maintained


--------------------------------------------------------------------------

      Live a more beautiful life

------=_NextPart_001_0071_01CAFD85.CD836AE0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

	<table cellpadding="5" width="805" align="center" border="0" style="font-family:Arial, Helvetica, sans-serif; size: .9em; background-color: #FFFFFF; border-right: #cccccc 1px solid; border-top: #cccccc 1px solid; border-left: #cccccc 1px solid; border-bottom: #cccccc 1px solid">
	  <tr>
		<td><p style="align: center;"><img src="cid:006d01cafd7d$6bb7d6f0$0202a8c0@home"></p></td>
	  </tr>
	  <tr>
		<td style="text-align: center; color:#FFFFFF; border-right: #ffffff 30px solid; padding-right: 10px; margin-top: 0px; padding-left: 10px; padding-bottom: 10px; border-left: #ffffff 30px solid; padding-top: 10px; width: 100%; background-color: #666666;" valign="top">
		<p>Great! You have successfully registered as a <span style="color: #42e0d1;">curb</span>appeal user....</p>
		<p style="color: #cccccc;">You are now in the privileged position of receiving updates on <span style="color: #FFFFFF;">the</span> new stylish venues to try out around the globe. As a registered member you are also entitled to receive <span style="color: #FFFFFF;">offers</span> negotiated especially for you.</p></td>
	  </tr>
	  <tr>
		<td><p style="align: center;"><img src="cid:006e01cafd7d$6bb7d6f0$0202a8c0@home"></p></td>
	  </tr>
	  <tr>
		<td style="text-align: center;">Say goodbye to the endless hours of surfing the web trying to find cool restaurants, cafes,<br />bars, hotels, spas....just 'curbappeal it'</td>
	  </tr>
	  <tr>
		<td><p style="align: center;"><img src="cid:006f01cafd7d$6bb7d6f0$0202a8c0@home"></p></td>
	  </tr>
	  <tr>
		<td><p>Don't forget, as this is a new website, there will be frequent uploads of more exciting venues for you to check out...so keep logging on to <a href="http://www.thisiscurbappeal.com" style="color: #000000; text-decoration: none">www.thisis<span style="color: #42e0d1;">curb</span>appeal.com</a> for new ideas.</p>
		  <p>If there are any venues you think should make it onto our site, then please contact us on<br />
	      <a href="mailto:info@thisiscurbappeal.com" style="color: #000000; text-decoration: none">info@thisis<span style="color: #42e0d1;">curb</span>appeal.com</a></td>
	  </tr>
	  <tr>
		<td>
		<hr color="#42e0d1" size="1" />
		<p style="font-size: .7em"><a href="mailto:info@thisiscurbappeal.com" style="color: #000000; text-decoration: none"><span style="color: #42e0d1;">curb</span></a>appeal: <em>noun</em><br />
		1. The visual attractiveness of a property as seen from the street<br />
		2. A Property that looks architecturally distinctive and well maintained</p>
		<hr color="#42e0d1" size="1" />
		<p style="text-align: center; font-size: .8em">Live a more <span style="color: #42e0d1;">beautiful</span> life</p>
		</td>
	  </tr>
	</table>

------=_NextPart_001_0071_01CAFD85.CD836AE0--

------=_NextPart_000_0070_01CAFD85.CD836AE0
Content-Type: image/png;
	name="top.png"
Content-Transfer-Encoding: base64
Content-ID: <006d01cafd7d$6bb7d6f0$0202a8c0@home>

<?php echo $top_png ?>

------=_NextPart_000_0070_01CAFD85.CD836AE0
Content-Type: image/jpeg;
	name="welcome-top.jpg"
Content-Transfer-Encoding: base64
Content-ID: <006e01cafd7d$6bb7d6f0$0202a8c0@home>

<?php echo $welcome_top_jpg ?>

------=_NextPart_000_0070_01CAFD85.CD836AE0
Content-Type: image/jpeg;
	name="welcome-bottom.jpg"
Content-Transfer-Encoding: base64
Content-ID: <006f01cafd7d$6bb7d6f0$0202a8c0@home>

<?php echo $welcome_bottom_jpg ?>

------=_NextPart_000_0070_01CAFD85.CD836AE0--

<?php
	$message = ob_get_clean();
	if (mail($to, $subject, $message, $headers)) { 
		$send_status = '<p>Mail sent</p>';
	} else {
		$send_status = '<p>Mail failed</p>';
	}
}
			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email Test</title>
<style type="text/css">
<!--
body {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
#mail_form {
	width: 400px;
	margin-top: 50px;
	margin-right: auto;
	margin-left: auto;
}
-->
</style>
</head>

<body>
<form method="post" action="" id="mail_form">
	<p><input type="text" name="email" value="" /></p>
	<p><input type="submit" name="submit" value="send" /></p>
	<?php echo $send_status ?>
</form>
</body>
</html>

Any help would be so greatly appreciated,

Simon.

Maybe the host is being bounced as spam?

It's not even getting that far ... the mail function fails. It would help if I knew how to retrieve some sort of error message - I just get True or False. I'm sure that there is a way to get more error detail .... I'm researching that one right now ...

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.