# CGI Error when sending php mail

**URL:** <https://forum.kirupa.com/t/cgi-error-when-sending-php-mail/256333>\
**Category:** programming\
**Created:** [April 2, 2008, 4:01am UTC](https://forum.kirupa.com/t/cgi-error-when-sending-php-mail/256333 "2008-04-02T04:01:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgomez84](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sgomez84/32/2962_2.png) [@sgomez84](https://forum.kirupa.com/u/sgomez84)\
**Post date:** [April 2, 2008, 4:01am UTC](https://forum.kirupa.com/t/cgi-error-when-sending-php-mail/256333/1 "2008-04-02T04:01:24Z")

</div>

Hi all,  
I created this page to send all my professors’ email. When I send the email I get this error.

```auto
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

```

```php
Code:
if (isset($_POST['sendmail'])) {
    //echo "<pre>";
    //print_r($_POST);
    //echo "</pre>";
    
    ini_set('sendmail_from','webmaster@jueconomics.in');
    $FromWho = "Sys Admin <webmaster@jueconomics.in>";
    
    $mailBody = $_POST['emailBody'];
    $emailTo = $_POST['toEmail'];
    $ccTo = $_POST['ccTo'];
    $subject = $_POST['subject'];
    $count = 0;
    
    if ($emailTo == "all") {
    
    
    $nameConcat = "";
    
        do {
        
        $nameConcat = $row_getEmails['FirstName']." ".$row_getEmails['LastName'];
        $priEmail = $nameConcat." <".$row_getEmails['Email1'].">";
        $secEmail = $row_getEmails['Email2'];
        
        $eachBody = $mailBody;
        $eachBody = str_replace("%Fullname%",$nameConcat,$eachBody);
        $eachBody = str_replace("%SecondaryEmail%",$row_getEmails['Email2'],$eachBody);
        
               
        if (!mail($priEmail, $subject, $eachBody, "From: $FromWho")) {
            echo "Error sending email";
            
            }            
            echo "Success!";
        
    
        $count++;                 
        
        } while ($row_getEmails = mysql_fetch_assoc($getEmails));
        
        
    }
        
    
    
}
?>

```

Someone please help me if I am going wrong. Need this urgently.

Thanks,  
Sid
