Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with mail()

Status
Not open for further replies.

dkdude

Programmer
Jun 16, 2003
849
DK
Hi,

I have a script that uses mail(). About half the time, the script works fine (the mail() part). The rest of the time, the mail simply don't get sent.

Since I use it for a newsletter, it is important, that the html mail is sent when I want it to -and only once.

Any ideas og suggestions to other working and reliable mail scripts?

Thanks a bunch!


Jakob
 
bit difficult to help on your script ...

how about supplying:

* your mail script
* an example that works
* an example that does not work
* the errors returned by your web server/php and your email server.

if you want to ditch your script and go for a standard class sleipnir214 regularly recommends phpmailer (hope i've got that right - i'd hate to attribute a recommendation falsely...)
 
Hi jpadie,

This is the script, that sometimes works -and sometime doesn't:

[tt]<?php
// to
$to = 'me@my.com' . ', ';
$to .= 'another@my.com';

// subject
$subject = 'Newsletter';

// message
$fil = fopen("newsletter.html", "r+");
while(!feof($fil))
$message .= fgets($fil, 512);
fclose($fil);

// headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "X-Priority: 1\n";
$headers .= "Importance: High\n";
$headers .= "X-MSMail-Priority: High\n";

// Additional headers
$headers .= 'To: Me <me@my.com>, Another <another@me.com>' . "\r\n";
$headers .= 'From: <contact@me.com>' . "\r\n";

// Mail it
$attempts = 0;
while((!$test)&&($attempts<50)) {
$test = mail($to, $subject, $message, $headers);
$attempts++;
}
if($test)
echo "Sent in attempt no. $attempts!";
else {
echo "Error : $test<br />";
echo "Attempt no. $attempts. failed...";
}
?>[/tt]

I don't get any text error back from mail(). Sometimes, the mail is sent in 1st go, sometimes in the n.th go, and sometimes it fails all 50 attempts...

Any ideas why?

Thanks again


Jakob
 
what os are you using?
have you tried out phpmailer()?
 
Hi jpadie,

I solved my problem -the problem was caused by an anti-spamming functionallity on my web hotel.

Thanks anyway!


Jakob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top