1

I am trying to get a mail/denounce type thing to work: There are mail groups, you join a mail group and leave a mail group, and you can send the whole mail group an email, by pressing a button, when you press the button you get directed to a page where you will put a form, then you click send

The following code runs:

    $new_subject = $_POST['subject'];
$new_message = $_POST['message'];
// subject and message posted from the forum
if ($new_subject&&$new_message){

    $query = mysql_query("SELECT * FROM mail_groups");
    while($row=mysql_fetch_assoc($query)){
    $id = $row['id'];
    }
// Selects all mail groups, and gets their ID
    $query6 = mysql_query("SELECT * FROM mail_group_members WHERE gid='$id'");
// Selects the members' email out of the specific mail group where the group id is ID
    while($row3=mysql_fetch_assoc($query6)){
        $send_to = $row3['email'];
    // sets the send_to variable, which is different to each user (this is the user's email) 

    mail($send_to,$new_subject,$new_message,$headers);
// tries to send email, but nothing happens, no error messages, nothing
}
header("Location: mail.php");
// redirects to main mail page
}

I have set the SMTP server in php.ini (as my ISP-s)

Thanks for all help in advance

  • 1
    are you running on a windows box? the smtp server does not apply to non-windows hosts. did you supply the username/password required for the smtp server, if necessary? did you check the return value of `mail()` to see if it failed (returns false if so). did you check the mail server's logs to see what happened to the email after php handed it over? – Marc B Nov 20 '12 at 16:52
  • Where is this PHP server? If it's on your local machine, it's fine, but if it's a remote server, your ISP's might not be the right SMTP server. – GolezTrol Nov 20 '12 at 16:53
  • I am running Windows 7 Ultimate (x64), I did check the return value of mail() and it returned true, and where can I see in the log what happened to the email? is it in access.log or error.log, and what would it look like? – Beni Burgess Nov 20 '12 at 16:57
  • Dig in SMTP server settings to see where "failed to deliver" mail will go. Maybe you are blocked by spam filters where you send the mail to or something similar, I assume `mail()` returning `true` means the mail is successfully sent. – Ranty Nov 20 '12 at 17:00
  • 1
    Where can I find the SMTP server settings? :/ – Beni Burgess Nov 20 '12 at 17:04
  • mail() returning true only means that the SMTP server accepted it for delivery, not that it was or will be successfully delivered. If mail() is returning true and the SMTP server is under your ISP's control, I'm afraid you are going to have to ask your ISP for assistance. Unless you have access to the server's mail logs, there's not much you can do to determine why the mail is not being sent. – mdoyle Nov 20 '12 at 17:21
  • Have you checked the output of your queries to make sure that you are getting expected results? The SMTP server will likely accept for delivery message that end up being undeliverable due to invalid recipient addresses. I'd make sure your queries are ultimately generating valid recipient addresses. – mdoyle Nov 20 '12 at 17:24
  • I made sure: I echo's out $id and $send_to and echo'd fine isn't there a way to create an SMTP server of my own? – Beni Burgess Nov 20 '12 at 17:28
  • Is there anything else I ought to change in php.ini? – Beni Burgess Nov 20 '12 at 17:30
  • Sure there is, spammers do it all the time. If you're talking about a residential ISP, though, there's little chance it will allow SMTP traffic generated by unauthorized servers to leave its network. – mdoyle Nov 20 '12 at 18:56

0 Answers0