lisawebs Posted September 3, 2007 Share Posted September 3, 2007 I have a set of codes to manage a simple mail list, everything's fine, except for this piece to send an email to each address, I can't figure out why this is not working, it doesn't give an error, but no emails are sent <html><head><title>sending....</title></head><body> <? $addresses = file("data/lista.lst"); for ($index=0; $index < count($addresses); $index++) { $Email = "$addresses[$index]"; mail("$Email","Welcome...","text here","From: IN21\nReply-To: alex@usa21.net"); } ?> Your message was sent! <br><br> <a href="index.php3">Home</a>. </body></html> the file lista.lst has only this inside: alexvvv@hotmail.com|lisawebs@yahoo.com| thanks! lisawebs@yahoo.com Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/ Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 It could be the fact that msn and yahoo usually do not accept emails from php mail(). Probably depending on your host. Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340447 Share on other sites More sharing options...
lisawebs Posted September 3, 2007 Author Share Posted September 3, 2007 the email issue with php when a visitor input an address works fine, the problem is in the loop to send an email to each address on the list. Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340470 Share on other sites More sharing options...
Timma Posted September 3, 2007 Share Posted September 3, 2007 Oh, your forgot to explode it $addresshandle = file("data/lista.lst"); $addresses = explode("|",$addresshandle) $addresses[0] should equal the first email and [1] should equal the second. Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340479 Share on other sites More sharing options...
lisawebs Posted September 3, 2007 Author Share Posted September 3, 2007 no, the lista.lst file contains only one email address per line, there are no such separators... this is strange, if there's no error msg then maybe the problem isnt in php but on the server, but where? Maybe the question is what in a server can prevent these emails to be sent... because the mail system in general is working fine, besides, I've just received an email from another php program running in my server ?????? I'm lost!! Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340522 Share on other sites More sharing options...
Azu Posted September 3, 2007 Share Posted September 3, 2007 If there is one e-mail per line instead of seperators Then maybe instead of $addresses = explode("|",$addresshandle) You should use $addresses = explode("\n",$addresshandle) ? Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340532 Share on other sites More sharing options...
lisawebs Posted September 3, 2007 Author Share Posted September 3, 2007 thanks, but is this EXPLODE() a php4 function??? or later because isnt working, gives error... Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340900 Share on other sites More sharing options...
darkfreaks Posted September 3, 2007 Share Posted September 3, 2007 <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340909 Share on other sites More sharing options...
lisawebs Posted September 3, 2007 Author Share Posted September 3, 2007 this last code works, when I use $addresses[$index] seems that nothing is passed again I dont know what's wrong here <html><head><title>sending....</title></head><body> <? $addresses = file("data/lista.lst"); for ($index=0; $index < count($addresses); $index++) { $to = "$addresses[$index]"; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers);} ?> Your message was sent! <br><br> <a href="index.php3">Home</a>. </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340922 Share on other sites More sharing options...
darkfreaks Posted September 3, 2007 Share Posted September 3, 2007 try <?php $to= "$addresses($index)"; $subject = 'the subject';?> Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340927 Share on other sites More sharing options...
darkfreaks Posted September 3, 2007 Share Posted September 3, 2007 <?php $addresses=file_get_contents('data/lista.lst'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-340930 Share on other sites More sharing options...
lisawebs Posted September 4, 2007 Author Share Posted September 4, 2007 None of the code hints worked, I'm lost... Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341002 Share on other sites More sharing options...
teng84 Posted September 4, 2007 Share Posted September 4, 2007 have you try to run simple mail to see if mail function work in your system Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341007 Share on other sites More sharing options...
lisawebs Posted September 4, 2007 Author Share Posted September 4, 2007 On code above, when the $to variable is set to "anyemail@domain.com" it works, msg is sent. But doing $to = $addresses[$index]; it never works, no matter how I write it (with "", with (), etc) the echo is right, it shows the right email, but the if (mail()... returns false... so what is this??? a) could be a var type issue? b) is it possible the server understand the emails comes from an array and discard them? Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341009 Share on other sites More sharing options...
teng84 Posted September 4, 2007 Share Posted September 4, 2007 i guess this is wrong $to = "$addresses[$index]"; try to change this to $to = $addresses[$index]; should work! Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341011 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 he is right you have it in quotes therefore it wont read the variable. Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341013 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 also it should be <?php $to= "$addresses($index)"; $subject = 'the subject';?> Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341015 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 try <?php $to= $addresses($index); $subject = 'the subject';?> without the quotes Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341018 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 also file needs to be changed to file_get_contents or it turns into an array Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341024 Share on other sites More sharing options...
teng84 Posted September 4, 2007 Share Posted September 4, 2007 @darkfreaks LOL Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341031 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 i think im repeating myself or something here?? ??? people should listen or at least check out http://us2.php.net/manual/en/function.file-get-contents.php Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341033 Share on other sites More sharing options...
Azu Posted September 4, 2007 Share Posted September 4, 2007 Whoa.. nice quadruple posts! Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341106 Share on other sites More sharing options...
Northern Flame Posted September 4, 2007 Share Posted September 4, 2007 is there a comma after each email address? Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341134 Share on other sites More sharing options...
darkfreaks Posted September 4, 2007 Share Posted September 4, 2007 Try: <?php { $email = trim($email); // clear any extra spaces in front and end of email address $past = 0; $valid = false; $dot = false; $message = NULL; if(strlen($email) > 0) // email is not empty { if(strstr($email, "@")) // find @ symbol in email { for($counter=0; $counter < strlen($email); $counter++) { if($email[$counter] == "@") { $prior= $counter +1; $past = 0; $dot = false; continue; } if($email[$counter] == "." && $past > 0) $dot = true; $past++; } // end for if($prior > 0 && $past > 0 && $dot == true) $valid = true; } // end if if ($valid == false) { $message = 'Your Email address does not seem right.'; } } else { $message = 'You forgot to enter your Email address.'; } return $message; }// end function ?> If this works Click Topic Solved! Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341586 Share on other sites More sharing options...
lisawebs Posted September 4, 2007 Author Share Posted September 4, 2007 Main solution was using the trim() The only problem with this code is the @hotmail.com addresses are not receiving emails (not even as junk) Yahoo and other mails are receiving normaly So I'll open a new issue about how to control the mail() info/headers to allow messages be accepted. Thanks to everyone!!! <? $addresses = file("data/lista.lst"); for ($index=0; $index < count($addresses); $index++) { $subject = 'the subject'; $message = 'hello'; $headers = 'From: lisawebs@yahoo.com' . "\r\n" . 'Reply-To: lisawebs@yahoo.com' . "\r\n"; if (mail(trim($addresses[$index]), $subject, $message, $headers)) echo "yes"; else echo "no"; } Quote Link to comment https://forums.phpfreaks.com/topic/67770-solved-why-this-mail-function-isnt-working/#findComment-341618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.