Having multiple of sender's email when email is received

Discussion in 'PHP' started by alimoses, Feb 11, 2012.

  1. #1
    Below is a php script fetches the name and email of all the employee from a table named reviewers and sends email to them addressing each employee by name.
    The script works but sometimes the employee receives the email and the sender's email appear many times.

    <?php
    $sql = "select email, name from reviewers where specialization='$_POST[specialization]' ";
    $result = mysql_query($sql) or die(mysql_error());

    if (mysql_affected_rows()>0){
    while ($reviewer = mysql_fetch_array($result)){

    $reviewerName = $reviewer['name'];

    // get d last char and remove if it not valid
    $emails = $reviewer['email'];
    $lastChar = getLastCharOfString($emails);
    if ($lastChar == "," || $lastChar == ";"){
    $emails = removeLastCharacter($emails);
    }
    $to = $emails;
    $subject = 'Invitation to Review : ' . $manuscriptCode;
    // Obtain file upload vars
    $fileatt = $_FILES['manuscript']['tmp_name'];
    $fileatt_type = $_FILES['manuscript']['type'];
    $fileatt_name = $_FILES['manuscript']['name'];

    $journalEmail = getJournalEmail($_GET['cd']);
    $headers[] = 'MIME-Version: 1.0';
    $headers[] = 'Content-type: text/html; charset="iso-8859-1"';
    $headers[] = 'Content-Transfer-Encoding: 7bit';
    $headers[] = 'From: '.$journalEmail; //
    $reviewer_message = ' <html> ';
    $reviewer_message .= '<div align="right"><img src="' . $logoUrl . '"/> <br/>'.$journalUrl.'<br>'.$journalEmail.'</div><br>';
    $reviewer_message .= '<div align="center"><b>'.$subject.'</b></div><br>';
    $reviewer_message .='Dear '.$reviewerName.',<br><br>';
    $revMsgPara1 ='We wish to inquire if you could create time to review the manuscript titled:<br><br>';
    $reviewer_message .= $revMsgPara1;
    // autoreply msg 1
    $revMsgPara2 = '<b>'.$_POST['articleTitle'].'</b><br><br>';
    $reviewer_message .= $revMsgPara2;
    $revMsgPara3 = 'Please find the abstract below:<br><br>';
    $reviewer_message .= $revMsgPara3;
    $revMsgPara4 = '<b>Abstract</b><br><br>'.$_POST['abstract'].'<br><br>';
    $reviewer_message .= $revMsgPara4;
    $revMsgPara5 = '<b><u>NB:</u><br><br>Kindly send us a mail to indicate your interest to review the submitted paper, if however the subject area covered by the manuscript is out of your scope of study or for time constraint or any other reason you may not be able to carry out the requested review, we would appreciate if more suitable reviewers could be recommended by sending the names and email addresses of the recommended reviewers to us in a mail, you may also send a mail to the recommended reviewers informing them about the paper submitted for review.</b><br><br>';
    $reviewer_message .= $revMsgPara5;
    $reviewer_message .='Best regards<br><br>';
    $reviewer_message .=$journalCode.' Editorial Team,<br>';
    $reviewer_message .='Email: <u>'.$journalEmail.'</u><br>';
    $reviewer_message .='<u>'.$journalUrl.'</u><br><br>';
    $reviewer_message .='<em><small>This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify . E3 JOURNALS and its employees make no representations as to the accuracy and completeness of the information contained in this email. We therefore accept no liability for any loss arising from the use of the information contained in this email. Finally, the recipient should check this email and any attachments for the presence of viruses. E3 JOURNALS and its employees accept no liability for any damage caused by any virus transmitted by this email.</small></em><br>';
    $reviewer_message .= '</html>';

    // Send the message
    $success2 = mail($to, $subject, $reviewer_message, join("\r\n", $headers));
    $journalEmail = "";
    }
    }
     
    alimoses, Feb 11, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    I have looked at your code but doesn't seem to see something wrong.

    PLEASE put code in the CODE tags next time [ code ] .... [ / code ]
     
    EricBruggema, Feb 14, 2012 IP
  3. adityamenon

    adityamenon Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    $journalEmail is populated using the function getJournalEmail() - please post the function contents here, as well as a sample data from $_GET['cd']. There is most probably a looping error in that function that is making your sender appear more than once...
     
    adityamenon, Feb 14, 2012 IP
  4. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Do you mean the same email is sent to the same person multiple times?
     
    Andre91, Feb 14, 2012 IP