Jump to content

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


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

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      = '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);
?> 

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>

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?

 

 

 

 

 

 

 

 

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: 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";  
} 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.