Click to See Complete Forum and Search --> : php mail() problems?
willg825
06-05-2003, 07:19 PM
Hey there. I'm having some difficulties with the mail() function. It works, but it seems to only work sporadically--i.e, sometimes it will send it, sometimes it wont. I dont understand why. Is this common? Is there a better, different way to send mail? The server is apache/red hat linux, but I dont have permission to use chmod so I cannot change permissions (so i cant open a pipe to sendmail, as ive seen it done as well.)
here is what the codelooks like (its coming from a form)
$email = $_POST["email"];
$to = "receivers@emailaddress.com"; // i receive it
if (!strstr($email, "@")) { // weak, but ok
echo "Not a valid email address, please try again...";
}
else {
if (mail($to, "CCC SUBSCRIPTION", $email, "From: CCC")) // it worked
echo "Thank you! $email has been added to the mailing list<p><br>";
}
anyone have any ideas? thanks!
Make sure your @ sign isn't escaped (e.g., \@ instead of what it should be: @).
Jona
willg825
06-05-2003, 09:00 PM
Jona.. thanks for the reply... but the @ isn't escaped, its just "myemailaddress@etc.com"
any other ideas? sometimes it works, othertimes it doesnt.. quite frustrating.
thanks,
will
Originally posted by willg825
[A]ny other ideas?
Yup. ;) Why put it in an if statement? Just to check and see if it can mail()? Try it without that if statement on there and see what happens.
Jona
willg825
06-05-2003, 09:59 PM
Jona.. Still no luck. I put that if statement there only because mail returns bool.. I removed it and still get the same problem
$email = $_POST["email"];
$to = "me@hidden.com"; // i receive it
if (!strstr($email, "@")) { // weak, but ok
echo "Not a valid email address, please try again...";
}
else {
mail ($to, "CCC SUBSCRIPTION", $email, "From: CCC"); // it worked
echo "Thank you! $email has been added to the mailing list.";
}
any more ideas? =D I am really stumped. Its not that it doesnt work; it works occasionally. More often though it doesnt work.
AdamBrill
06-05-2003, 11:02 PM
That didn't work for you? It worked fine for me... Try the attached code and see if that works. ;)
willg825
06-05-2003, 11:46 PM
Heya Adam, Thanks for the reply
I ran your script, and similar results appeared. The first time i ran it, I got the email just fine. But I couldn't run it again (2nd, 3rd, 4th, 5th times, etc.) I tried restarting explorer, refreshing, etc. etc. It just wouldn't email me again (just the first time.)
Very frustrating indeed. Any ideas on this? Have you gotten it to work more than once? Is it likely a problem with the sendmail on the server?
thanks,
will
AdamBrill
06-06-2003, 07:21 AM
I tried it multiple times on my server and it works fine. Does it give you an error when it doesn't work, or does it just not send the e-mail? If it gives you an error, what does it say?
Originally posted by willg825
Is it likely a problem with the sendmail on the server?Yes, more than likely, that is the problem, as you code looks fine to me.
willg825
06-06-2003, 09:38 AM
bleh. ok. i'll have to figure this out from the server
thanks for all your help...
no error messages.. just only sends it occasionally
will
eraguet
06-09-2003, 04:25 PM
hi
maybe you should take a better care of your headers ??
here is what you can find on php.net :
//$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: me<".$MY_MAIL.">\r\n";
$headers .= "To: you <".$your_mail.">\r\n";
$headers .= "Reply-To: me <".$MY_MAIL.">\r\n";
//$headers .= "X-Priority: 1\r\n";
//$headers .= "X-MSMail-Priority: High\r\n";
//$headers .= "X-Mailer: PHP / ".phpversion()."\r\n";
sometimes provider such as yahoo block some kind of mail because the headers are not properly defined ...
i expect it will help you...
ed