Jay
Jay

Reputation: 402

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 = '[email protected]';
            $subject = 'Hello';
            $name='my name';
            $from="[email protected]";

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

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

            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.

Upvotes: 3

Views: 10715

Answers (3)

Bikram Shrestha
Bikram Shrestha

Reputation: 2070

use the code sample as below, email address in <> and that last paramter worked for me.

$headers = 'From: <[email protected]>' . "\r\n" .
'Reply-To: <[email protected]>';

mail('<[email protected]>', 'the subject', 'the message', $headers,
  '[email protected]');
?>

It is the answer provided in PHP mail() function will not send to gmail but will send to my non-gmail account by ARH3, which i have tried and tested

Upvotes: 0

MJ Khan
MJ Khan

Reputation: 1746

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

    if( mail( $recipient, $subject, $message, $headers, "-f [email protected]"))
        return "success";

Upvotes: 3

Sajal
Sajal

Reputation: 1216

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.

Upvotes: 0

Related Questions