PHP mail function not sending email to Gmail account?

I am working on a WordPress plugin in which I send email using the PHP mail function, but there is a problem with the mail function. It sends emails to my non-Gmail account, but it’s doesn’t send emails to my Gmail account. I am using following code:

function send_mail()
        {
            global $wpdb;
            $to = 'mymail@gmail.com';
            $subject = 'Hello';
            $name='my name';
            $from="name@mydomain.com";

            $message = "
            <html>
            <head>
            <title>my title</title>
            </head>
            <body>
            <div>
                <tt> ".Hii How Are you."</tt>
            </div>
            </body>
            </html>";

            $header  = "MIME-Version: 1.0rn";
            $header .= "Content-type: text/html; charset=iso-8859-1rn";
            $header .= "From: ".$name."<".$from.">rn";

            mail($to, $subject, $message, $header);
}

Is there something wrong with my code, or is there some issue with the mail function? If any alternate method is available to send email, please give me the link.

Related posts

Leave a Reply

3 comments

  1. Check if adding fifth variable works for you… here is my code for sending emails.

        if( mail( $recipient, $subject, $message, $headers, "-f noreply@mydomain.com"))
            return "success";
    
  2. Check the spam folder, It might be there. Its a server issue, it hapened to me also many times. Gmail blocks mails or sends to spam from some servers due to some reasons. Ask your server provider to check why mails are not going to gmail inbox.