Search code examples
phpgmailmime

Why isn't my gmail or yahoo email accounts receiving mail when I use this PHP mail function


The send_mail function with the headers. What could be blocking this from being received. I know it works at least sometimes, my work email receives it just fine.

Another thing that might be of note: - with a different ssl page the function did send correctly to gmail - on this totally separate domain, it is not.

function send_mail($from,$fromName,$to,$object,$bodyText,$bodyHtml){
    $site = "mywebsite.ca";
    $from = $fromName." <".$from.">";
    $limite = "_----------=_parties_".md5(uniqid (rand()));

    $header  = "Reply-to: ".$from."\n";
    $header .= "From: ".$from."\n";
    $header .= "X-Sender: <".$site.">\n";
    $header .= "X-Mailer: PHP\n";
    $header .= "X-auth-smtp-user: ".$from." \n";    
    $header .= "X-abuse-contact: ".$from." \n"; 
    $header .= "Date: ".date("D, j M Y G:i:s O")."\n";
    $header .= "MIME-Version: 1.0\n";
    $header .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";

    $message = "";
    $message .= "--".$limite."\n";
    $message .= "Content-Type: text/plain\n";
    $message .= "charset=\"iso-8859-1\"\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= $bodyText;

    $message .= "\n\n--".$limite."\n";
    $message .= "Content-Type: text/html; ";
    $message .= "charset=\"iso-8859-1\"; ";
    $message .= "Content-Transfer-Encoding: 8bit;\n\n";
    $message .= $bodyHtml;

    $message .= "\n--".$limite."--";
    if(mail($to, $object, $message, $header)) return true;
    else return false;
}

Solution

  •  if(mail($to, $object, $message, $header)) return true;
        else return false;
    

    heres the code that send the mail to your email try to debug it it all the variable inside specially the $to varible because its your email where the message will be send.

    try this

    if(mail($to,$object,$message,$header)){
          //echo all
    }
    else{
          //echo mssage not submit
    }