Jump to content

[SOLVED] why this MAIL function isn't working?


lisawebs

Recommended Posts

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: [email protected]");
}
?>
Your message was sent!
<br><br>

<a href="index.php3">Home</a>.
</body></html>

the file lista.lst has only this inside:
[email protected]|[email protected]|

 

thanks!

[email protected]

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

<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

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: [email protected]' . "\r\n" .
        'Reply-To: [email protected]' . "\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>

On code above,

when the $to variable is set to "[email protected]"

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?

 

 

 

 

 

 

 

 

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!

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: [email protected]' . "\r\n" . 
           'Reply-To: [email protected]' . "\r\n"; 
if (mail(trim($addresses[$index]), $subject, $message, $headers)) 
    echo "yes";  
else 
    echo "no";  
} 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.