SitePoint Sponsor

User Tag List

Results 1 to 24 of 24

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help please email function not working.

    Hi all, I am having a problem but I am not sure why this Email function is not working. This is my script to send out a short newsletter to some people on the website. It pulls their email address if they have the newsletter feature enabled. When i run the script it says how many emails were sent. But the emails never go thru. I dont get any errors. Currently 9 emails should be sent and It says they were. But the emails never get delivered. If anyone can help me to figure out why the emails are not going thru I would appreciate it much. Thank all.

    PHP Code:
    if(isset($_POST[s1])) 

            
    //get the subscribers info 
            
    $q1 "select * from news_as where news = 'y' "
            
    $r1 mysql_query($q1) or die(mysql_error()); 
             
            while(
    $a1 mysql_fetch_array($r1)) 
            { 
                    
    $to $a1[email]; 
                    
    $subject $_POST[subject]; 

                    
    $headers "MIME-Version: 1.0\n"
                    
    $headers .= "Content-type: text/$a1[NewsletterType]; charset=iso-8859-1\n"
                    
    $headers .= "Content-Transfer-Encoding: 8bit\n"
                    
    $headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"
                    
    $headers .= "X-Priority: 1\n"
                    
    $headers .= "X-MSMail-Priority: High\n"
                    
    $headers .= "X-Mailer: PHP/" phpversion()."\n"

                    if(
    $a1[NewsletterType] == "plain"
                    { 
                            
    $message strip_tags($_POST[message]); 
                            
    $message .= "\n\n========================\nTo unsubscribe, use this link:\n"
                            
    $message .= "$site_url/u.php?id=$a1[AgentID]"
                    } 
                    else 
                    { 
                            
    $message $_POST[message]; 
                            
    $message .= "<br><hr width=\"100%\" size=1 color=black>Click <a href=\"$site_url/u.php?id=$a1[NewsID]\">here</a> to unsubscribe."
                    } 

                    
    $message stripslashes($message); 

                    
    mail($to$subject$message$headers); 

                    
    $i++; 
            } 

            
    //add the message to the mail archive
            
    $t time();
            
    $q1 "insert into d_m_archive set
                                            subject = '
    $_POST[subject]',
                                            message = '
    $_POST[message]',
                                            MailDate = '
    $t' ";
            
    mysql_query($q1) or die(mysql_error());

            echo 
    "<center><b>$i emails have been successfully sent!</b></center><br>";





    //get the subscribers number 
    $q1 "select count(*) from news_as where news = 'y' "
    $r1 mysql_query($q1) or die(mysql_error()); 
    $a1 mysql_fetch_array($r1); 

    if(
    $a1[0] == '0'

            echo 
    "<br><center><font face=verdana size=2 color=red><b>You have no subscribers at your mailing list!"
            exit(); 


    ?> 

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use var_dump() or echo the variables involved in sending the mail.

    var_dump() the call to mail()

    turn up error reporting.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Clamcrusher, you know I am a newb, and whenever i post a new thread your advice is usually right on the money and I resolve alot of issues thanks to your advice. So thanks. I am not sure how to use vae_dump() the call to mail() feature.. I am sorry but can you please explain hot o add that into my code?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var_dump(mail(...));

  5. #5
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok this is what I got... I have no idea exactly what to do now..

    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL
    Warning: mail() expects at least 3 parameters, 1 given in /home/content/a/l/p/a/html/siteadmin/Mail.php on line 16
    NULL

    line 16: var_dump(mail($a1['email']));

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    give it all 4 parameters...

  7. #7
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay how do I do that Clamcrusher?

  8. #8
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The mail function takes at least 3 parameters. $to, $subject, $message, and $headers are all parameters.

    This is what it should look like:

    PHP Code:
    var_dump(mail($to$subject$message$headers)); 

  9. #9
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what I got...


    bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true)
    9 emails was sent!

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then you need to look at the 4 parameters and make sure they are appropriate.

    consider sending a plain text hello world type email to test.

  11. #11
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I do that?

  12. #12
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var_dump() your variables.

    see the documentation for the mail() function to see how to send a basic email. the point is: send a basic one to see if it works. it doesnt matter if the email is not what you want.

  13. #13
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok It is echoing the correct email addresses that are saved in the database but one of them is mine and i never get the email

  14. #14
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok i var dumped my variables here is what came up...:
    string(7) "[email]" string(9) "[subject]" string(9) "[message]" string(14) "[ContactEmail]"

    i var dumped them like this:
    var_dump('[email]', '[subject]', '[message]', '[ContactEmail]');

  15. #15
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var_dump($var);

    see the documentation...

  16. #16
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Clamcrusher, This is what I get.

    string(19) "vinny917@yahoo.com" string(5) "test " string(97) "test ======================== To unsubscribe, use this link: http:www.netfreakz.com/u.php?id=24" string(196) "MIME-Version: 1.0 Content-type: text/stripslashes(plain); charset=iso-8859-1 Content-Transfer-Encoding: 8bit From: www.netfreakz.com <> X-Priority: 1 X-MSMail-Priority: High X-Mailer: PHP/4.3.11 "

  17. #17
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doesnt that look a bit funny to you?

  18. #18
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No should it? I am not sure what looks funny. Can you please help me Clamcrusher?

  19. #19
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is how i vardumped:
    var_dump($to, $subject, $message, $headers); did i even do it right?

    when i var dump like this:
    var_dump(mail($to, $subject, $message, $headers));
    i get this:
    bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true) bool(true)

  20. #20
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    look at your content type and your from headers.

  21. #21
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok i tried to fix it and this is what i get:
    NULL string(4) "test" string(4) "test" NULL

  22. #22
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Clamcrusher I got it working but I had to pull out the line of code that was supposed to put the from email address into the email that goes out. This is the line of code it seems it wasnt pulling the email address out of the database. That was the problem <$aset[ContactEmail]>

  23. #23
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    more like its undefined. had you turned up error reporting, it would have been obvious. continually, you do not turn up error reporting. errors are good. you want to see them. i dont know why i keep repeating myself over and over for you, seems like it does no good.

  24. #24
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry I do not mean to frustrate you or make you feel like a broken record or answering machine. I didn't know how to imply the error reporting.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •