I cannot send emails more than 5 in php

i have some trouble here.

i m tying to send emails from my database where i have email column and in that column i have number of emails in there but when i try to insert more than 5 emails in my email column the Code i placed to send email is wouldn’t be worked.one more thing i worked from 000webhost sever not on localhost.and using mail function.

here is my php file

<?php
if (isset($_POST['submit'])) {
  $text = $_POST['text'];
  $user_email = $_POST['user_email'];
  if ($user_email == '') {
    $select_id = "<h4><center>select your e-mail id first!</h4></center>";
  } elseif ($text) {
    $sql = "INSERT INTO senior_registered_post (user_id,text,date_time) VALUES ('$user_email','$text')";
    mysqli_query($db, $sql);
    $solution = mysqlI_query($db, "SELECT * FROM 
    senior_registered_users WHERE user_id='" . $_SESSION["user_id"] . "'");
    $row = mysqli_fetch_array($solution);
    $first_name = $row['first_name'];
    $subject = $row['subject'];
    $email = $row['email'];
    $email_list = "";
    $sql = "select email from email";
    $result = mysqli_query($db, $sql);
    while ($row = mysqli_fetch_array($result)) {
      if (!empty($row['email'])) {    //if email column is not empty
        $email_list .= $row['email'] . ",";
      }
    }
    $email_list = rtrim($email_list, ',');    //trim the rightmost ',' and remove it e.g abc,abd
    echo $to = "$email_list"; // add one by one email id and send it                                           
    $subject = "$subject";
    $header = "from:$first_name<$email>";
    $message = " $text  ";
    if (mail($to, $subject, $message, $header)) {
      echo "<div class='alert alert-success alert-dismissable fade in'>";
      echo"<a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>";
      echo"E-mail send succesfully on registered E-mail Addresses";
      echo " </div>";
    } else {
      echo '<div class="alert alert-dismissable fade in">';
      echo '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>';
      echo '  Error! please Try After Sometime';
      echo '</div>';
    }
  } else if ($user_email == '') {
    $select_id = "<h4><center>select your e-mail id first!</h4></center>";
  } else {
    $textfield = "<h4><center>Please fill-out the Text fields first!</center></h4>";
  }
}
?>

when i pressed the submit button if email column in my database contain more than 5 emails then its says Error! please Try After Sometime it’s worked perfectly under <=5 email but more than that not.please if anybody have any idea were i am getting wrong please help i m new to php. any small help is appreciated.

You mean you want to get the emails in the database and send emails to them?

1 Like

yes!! i wanted to do but wouldn’t

Let’s be clearer, what do you exactly want so I can write the code?

1 Like

the code is successfully worked it fetches the all emails from database and send the email individually.but only send if emails addresses in the database column <=5

i have a comment box and i have a table in the database were i put all the emails in a column now i wanted to send the email to all my recipients what ever i typed in that commentbox

Why not do a while sql fetches, send the emails, instead of trimming and doing all that stuff?

1 Like

this php code help me to fetch the all emails from database and put the comma to separate them

look below if i wouldn’t use the line of code rtrim($email_list, ‘,’);

example:abc@gmail.com,def@gmail,

this result it wouldnt be accept by mail function bcz of extra coma at def@gamil.com,

thats y i use rtrim to remove the comma def@gamil.com

bcz i have to send email to all my recipients at once

Actually, I can’t help you alot, I’m not on my PC, I’ll write a nice code tomorrow, or another moderator will help you further :slight_smile:

1 Like

ohky.but don’t might be forget i m waiting for you reply.take your time sir.

Don’t worry, I’ll set a topic reminder :wink:

1 Like

ohky dont close the conversation

1 Like

Hi @navjot789!

I have managed to send test e-mails from both your websites without problems. Our mailing nodes are not down, which means the problem is either from your code or from your e-mail provider.


Also, I have noticed that the content of website https://kindelcryon.000webhostapp.com/ is in contradiction with our Terms of Service.

We do allow you to send e-mails from our servers, however we do not allow you to send spoofed e-mails for spamming/scamming purposes or such. Please remove the forbidden content of that website within 24 hours, otherwise your account will be suspended without recall.

Sorry i was just testing it i m not spoofing to anybody. I have problem with my www.studynots.tk website not with kindelcryon

I have problem with endogamic-blinks.000webhost

Sorry i was just testing it i m not spoofing to anybody.

Please remove the content.

I have problem with my www.studynots.tk website not with kindelcryon

The problem is certainly in your code.
I just saw one bug:

$sql = "INSERT INTO senior_registered_post (user_id, text, date_time) VALUES ('$user_email', '$text')";

user_id is incrementing automatically?

1 Like

Yes! Its automatically increases ohkey i removed it but still its dosn’t send more than 5 emails

I removed the content from kindelcryon