Why this SEND EMAIL is not working?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

Why this SEND EMAIL is not working?

Post by lisawebs »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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 the no emails are sent

Code: Select all

<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|


the whole thing is in usa21.net/maillist
thanks!

lisawebs@yahoo.com


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Use trim() to remove the end-of-line sequence from each address. Also check the return value of mail() so you know whether the server says it sent or not.
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

How

Post by lisawebs »

thanks! how could I get the mail() response from server???????
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

Same

Post by lisawebs »

when using explode,
the echo() shows Array, not the content,
either with "" or without
when using $addresses = File(...
the echo shows the content,

how could I test the mail() to know if the server
sent the msg?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Same

Post by Chris Corbyn »

lisawebs wrote:when using explode,
the echo() shows Array, not the content,
either with "" or without
when using $addresses = File(...
the echo shows the content
explode() returns an array so you have to loop over its elements like you were doing with file().
lisawebs wrote:how could I test the mail() to know if the server
sent the msg?

Code: Select all

//instead of just
mail( .... );

//..do this
if (mail( ... )) {
   echo "sent";
} else {
  echo "not sent";
}
lisawebs
Forum Commoner
Posts: 44
Joined: Wed Nov 19, 2003 6:21 pm

Almost done...

Post by lisawebs »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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!!!

Code: Select all

<?
$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";  
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply