Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 938071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:34:54+00:00 2026-05-15T21:34:54+00:00

I have a PHP mail script that successfully sends emails to everything BUT GMail

  • 0

I have a PHP mail script that successfully sends emails to everything BUT GMail addresses, so now I’m trying to create one with PEAR’s Mail and Mail_Mime packages that can send to GMail. I’ve gotten the impression that this is only possible if I connect through GMail’s SMTP server to send the messages. Upon trying a simple test script, I get the following error:

unable to set sender to
[username@gmail.com]

There is nothing wrong with the address, and this site suggests that if there’s nothing incorrectly formatted about the address, then it’s a server connectivity issue. But how do I troubleshoot a connectivity problem in this situation? Or is there something else I’m doing wrong? Or is there another, easier way to get a PHP script to successfully send mail to GMail?

My code is as follows (email address and password changed, obviously)

$from = "username@gmail.com";
$to = "username@gmail.com";
$subject = "Test";
$crlf = "\n";
$text = 'Text message';
$html = '<html><body>HTML message</body></html>';
$headers = array (
    'From' => $from,
    'Return-Path' => $from,
    'Subject' => $subject
);

$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);

$smtp = Mail::factory(
    'smtp',
    array (
        'host' => 'ssl://smtp.gmail.com',
        'port' => 465,
        'auth' => true,
        'username' => "username@gmail.com",
        'password' => "password",
        'debug' => true
    )
);

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo("<p>" . $mail->getMessage() . "</p>");
    echo 'FAILURE';
} else {
    echo 'SUCCESS';
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:34:55+00:00Added an answer on May 15, 2026 at 9:34 pm

    I can’t imagine why a simple username@gmail.com address wouldn’t work, so it’s probably another error masquerading as that. Make sure you’re not accidentally suppressing error messages (put a call to error_reporting(E_ALL) before you call send).

    One thing to keep in mind, though, is that you do not need to use GMail’s SMTP server to send mail to GMail addresses. You can use one provided with your hosting to the same effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One way to create a char/block device driver. Your application… May 16, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer The simplest solution is to look for /[.]log$/ in $f1… May 16, 2026 at 5:30 pm
  • Editorial Team
    Editorial Team added an answer There is no supported way, that I'm aware of, to… May 16, 2026 at 5:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a script that uses PHP mail() function to send emails: mail(me@mydomain.com, Subject,
I have a PHP script that sends critical e-mails. I know how to check
I have a simple PHP script that sends a message to a specified email
I have created an php mail script, And in the message of the mail
I have a PHP script that launches another script in the background. Recently my
in my website i've a PHP script that automatically mails to my customers a
i have been asked the php mail() function, is it send from linux ?or
I have a mail function, and it works fine, I get mails. But the
Forgive me for this noob question, but is there such a setting that sets
I'm having an issue with a simple PHP mailer. I've had this script working,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.