Google Answers Logo
View Question
 
Q: Sending emails via PHP script fails sometimes ( No Answer,   1 Comment )
Question  
Subject: Sending emails via PHP script fails sometimes
Category: Computers > Programming
Asked by: coolshop-ga
List Price: $15.00
Posted: 27 Jul 2003 09:01 PDT
Expires: 28 Jul 2003 17:23 PDT
Question ID: 235641
I am using a PHP script to send email to one or more recipients.  If
multiple recipients, the field "$Email" would be as follows:

email1@whatever.com,email2@whatever.com

The emails seems to be reaching some recipients and not others, in a
pattern that I cannot figure out.  Is something wrong with this script
that may be causing this?



<?php

if ($sendemail!="none") {


	if (($sendemail=="ups") || ($sendemail=="fedex") ||
($sendemail=="airborne")) {
		$title="Tracking Number";
	} elseif ($sendemail=="noavs") {
		$title="** Problem with your order **";
	} else {
	
		$title="Status Update";
	}

	echo "Start send $title to $Email<br>";


	$mail = TempNam("/tmp","$Email");
	$fd = fopen($mail,"w");
	fputs($fd,"From: Whatever.com <shop@whatever.com>\n"); /* Any Headers
*/
	fputs($fd,"To: $Email\n");
	fputs($fd,"Subject: Whatever Order $inv $title\n");
	fputs($fd,"\n\n"); /* Seperates Header from Body */



		fputs($fd,"This email confirms that we have received\n");
		fputs($fd,"and processed your order. \n");
		fputs($fd,"Your item(s) will ship from our\n");
		fputs($fd,"warehouse within the next\n\n");

		fputs($fd,"$numdays\n\n");

		fputs($fd,"business days\n\n");

		fputs($fd,"When the item ships from our warehouse, w\n");
		fputs($fd,"will send you another email confirming its\n");
		fputs($fd,"shipment, along with the \n");
		fputs($fd,"tracking numbers so that you can await and\n");
		fputs($fd,"track its arrival! \n\n");

		fputs($fd,"When you receive your unit, please be sure\n");
		fputs($fd,"and send us a photo of your cat(s) enjoying\n");
		fputs($fd,"it for our Kitty Customer Photo Gallery.\n\n");

		fputs($fd,"Thank you again for your order and please\n");
		fputs($fd,"contact me with any questions that arise.\n\n");




	fclose($fd);
	system("/usr/sbin/sendmail  -oi -t < $mail"); /* pipe to sendmail */
	unlink($mail);
	echo "<img src=1.gif height=15><p>mailed $Email<p><a
href=index.php3>Home</a>";

}

?>

Request for Question Clarification by sycophant-ga on 28 Jul 2003 02:35 PDT
Hi coolshop,

Is there any reason you are not using the mail() command?

As you have Sendmail installed locally, there is no reason that the
mail command shouldn't work.

http://nz2.php.net/manual/en/function.mail.php

Let me know if you have any problems with that. If it's not suitable,
I can suggest other ways of working around it.

Regards,
Sycophant-ga

Clarification of Question by coolshop-ga on 28 Jul 2003 06:00 PDT
Hello

In an effort to eliminate anything stupid on my site, I tracked down
this routine and am now using it.  What I am finding is that one
particular vendor is still unable to receive emails generated via this
method:

给多个地址发邮件的类 
  

<?php 

//////////////////////////////////////////////////////////// 
// EmailClass 0.5 
// class for sending mail 
// parameters 
// ---------- 
// - subject, message, senderName, senderEmail and toList are required
// - ccList, bccList and replyTo are optional 
// - toList, ccList and bccList can be strings or arrays of strings 
// (those strings should be valid email addresses 
// 
// example 
// ------- 
// $m = new email ( "hello there", // subject 
// "how are you?", // message body 
// "paul", // sender's name 
// "foo@foobar.com", // sender's email 
// array("paul@foobar.com", "foo@bar.com"), // To: recipients 
// "paul@whereever.com" // Cc: recipient 
// ); 
// 
// print "mail sent, result was" . $m->send(); 
// 
// 
// 

if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) { 
define('MAIL_CLASS_DEFINED', 1 ); 

class email { 

// the constructor! 
function email ( $subject, $message, $senderName, $senderEmail,
$toList, $ccList=0, $bccList=0, $replyTo=0) {
$this->sender = $senderName . " <$senderEmail>"; 
$this->replyTo = $replyTo; 
$this->subject = $subject; 
$this->message = $message; 

// set the To: recipient(s) 
if ( is_array($toList) ) { 
$this->to = join( $toList, "," ); 
} else { 
$this->to = $toList; 
} 

// set the Cc: recipient(s) 
if ( is_array($ccList) && sizeof($ccList) ) { 
$this->cc = join( $ccList, "," ); 
} elseif ( $ccList ) { 
$this->cc = $ccList; 
} 

// set the Bcc: recipient(s) 
if ( is_array($bccList) && sizeof($bccList) ) { 
$this->bcc = join( $bccList, "," ); 
} elseif ( $bccList ) { 
$this->bcc = $bccList; 
} 

} 

// send the message; this is actually just a wrapper for 
// PHP's mail() function; heck, it's PHP's mail function done right
:-)
// you could override this method to: 
// (a) use sendmail directly 
// (b) do SMTP with sockets 
function send () { 
// create the headers needed by PHP's mail() function 

// sender 
$this->headers = "From: " . $this->sender . "\n"; 

// reply-to address 
if ( $this->replyTo ) { 
$this->headers .= "Reply-To: " . $this->replyTo . "\n"; 
} 

// Cc: recipient(s) 
if ( $this->cc ) { 
$this->headers .= "Cc: " . $this->cc . "\n"; 
} 

// Bcc: recipient(s) 
if ( $this->bcc ) { 
$this->headers .= "Bcc: " . $this->bcc . "\n"; 
} 

return mail ( $this->to, $this->subject, $this->message,
$this->headers );
} 
} 


} 
?>

Request for Question Clarification by sycophant-ga on 28 Jul 2003 13:25 PDT
Hi coolshop,

It's hard to imagine why it may not work for only one vendor. But I
doubt the problem lies with PHP.

Are you able to send them an email any other way from that server? Do
you have a shell account you can run pine, elm or mail from?

Check they have properly form DNS records, and that their mail servers
are reachable from the server.

Make sure you se a return address on your emails so that any mail
daemon errors can be returned to you.

If you can, check the mail logs on the server, it maybe that they are
being delivered, but are somehow failing at the user's end.

Tracking down email errors can be a hard job, good luck.

Let me know what you find out, if anything.

Regards,
Sycophant-ga

Clarification of Question by coolshop-ga on 28 Jul 2003 17:23 PDT
OK, it appears that the one vendor had some new spam blocking in place to 
cause this problem.  I appreciate the time and effort on this, thanks again to all!
Answer  
There is no answer at this time.

Comments  
Subject: Re: Sending emails via PHP script fails sometimes
From: skitso-ga on 28 Jul 2003 17:05 PDT
 
There are several reasons one would not wish to use PHP's built in
mail function.

The server I operate on sends out automatic headers on all PHP mail,
used "to track spam". All they do is set off spam detection software
and simly get in the way, as my host puts them into the message body,
which is ridiculous. Manually administering the comands seems to stop
this.

I've also noticed that on Yahoo they detect mail from my server's
mail() function as "bulk mail", but yet when I use sockets and send
via SMTP, they do not label it bulk.

Coolshop has since switched, probably because he does not have my
problems.

Regarding your question, I didn't quite catch the clarification. You
say "给多个地址发邮件的类" doesn't work. That looks like a bunch of
odd characters to me, could you restate the problem?

If you are familiar with PHP, there are A NUMBER of posts made at
http://php.net/mail that speak about headers and the correct order of
them to enable the message to get through.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy