简体   繁体   中英

PEAR: Mail Mime - Can't send email after uploading to hosting site - GoDaddy

I've been creating this project, where the system accepts registration and then send the information thru mail to the owner. I'm using PEAR: Mail Mime to do this. Sending of mail is actually working on my local computer, but after uploading this project to a hosting site (GoDaddy), it's not sending anymore.

I did an error check to see what hinders the sending of mail, and I received this message:

Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )]

I'm using a GMail account to send email messages, and use this code to do it:

/* INCLUDE PREREQUISITES IN ORDER TO SEND AN EMAIL */
include('../../application/third_party/Mail-1.3.0/Mail-1.3.0/Mail.php');
require_once '../../application/third_party/Mail_Mime-1.10.0/Mail_Mime-1.10.0/Mail/mime.php';

/* HEADER INFORMATION */
$from = '<***@gmail.com>';
$to = '<***@gmail.com>';
$subject = 'Someone registers';
$crlf = "\r\n";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

// CREATING THE MIME MESSAGE
$mime = new Mail_mime($crlf);

$html = '
    <html>
        <body>
            Message here
        </body>
    </html>';

// SETTING THE BODY OF THE EMAIL TO HTML
$mime->setHTMLBody($html);

$body = $mime->get();
$headers = $mime->headers($headers);

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

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

if (PEAR::isError($mail)) {
    $errormessage = '<p>'.$mail->getMessage().'</p>'; // ERROR MESSAGE
    $mail->getUserInfo();
}

Yes, I turned on the Access for less secure apps of the GMail sender account.

And yes, the error displaying is turned on.

ini_set('display_errors', 1); 
error_reporting(E_ALL);

Any solutions that I might have missed?

Found an answer regarding the outgoing mail in this - Sending email through gmail SMTP on GoDaddy .

It is because of the hosting provider, GoDaddy, which restricts the SSL port of GMail (465), and other ports such as 25 and 587. Thanks to this article - Troubleshooting PHPMailer Problems - of GitHub for clearing that up. Users are resorted to use the mail-server of GoDaddy instead.

But I still managed to send an email using GMail by doing:

$smtp = Mail::factory('smtp');
/* SETTINGS WILL BE IN DEFAULT (E.G. HOST:LOCALHOST, PORT: 45) */

instead of

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

But the receiver receives the sent email as "spam" - result will be that the receiver won't notice the incoming emails from the system (not a good choice). And there are no records in the Sent items of the sender (means you "used" the email to send an email, but not entirely).

So, we are back with the mail-server of GoDaddy. First, you have to determine the relay server of your hosting account by checking this What is the name of my hosting account's relay server? , which was published by GoDaddy themselves. In my case, Linux (cPanel), which I'll be using localhost as my host.

$smtp = Mail::factory('smtp', array(
    'host' => 'localhost',
    'auth' => true,
    'username' => '***@***.com',
    'password' => '***'
));

But the weird thing is, there are still no records of sent items. Hope a GoDaddy representative reads this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM