[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2098
  • Last Modified:

phpmailer and gmail

require_once 'PHPMailer_5.2.1/class.phpmailer.php';

$mail = new PHPMailer(true);

try {
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "localhost"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "gmail@gmail.com";  // GMAIL username
$mail->Password   = "password";            // GMAIL password
  $mail->From = $mail->Username;
  $mail->FromName = "from";

  $mail->Body = 'body';

  echo "Mail was sent.</p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!

echo '<br>end of php';

Open in new window

phpmailer script works on localhost windows desktop

but for shared server linux (1and1.com, godaddy.com)

SMTP -> ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host.

and on a dedicated windows host
SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (12625808)
SMTP Error: Could not connect to SMTP host.
3 Solutions
1and1.com, godaddy.com have their own email (SMTP) servers ... why not use them?  (I suspect locking you into using theirs is part of their revenue model).
Loganathan NatarajanLAMP DeveloperCommented:
$mail->Host       = "localhost"; // SMTP server

are you sure the above "localhost" has configured SMTP server? You should ask your hosting people whether you can use this address to send /receive emails?

You must check with them whether they've enabled SMTP to send/receive mails
Loganathan NatarajanLAMP DeveloperCommented:
Check whether this help? Help
Ray PaseurCommented:
Shared hosting companies often disable this functionality because they have found that it is frequently used by spammers.  GoDaddy and 1and1 have been two of the most notorious hosts for spammers.  Now that spamming is illegal and the law can reach the hosting company, these hosting companies are at legal risk if they leave holes open for spammers.  

You might want to consider dedicated hosting with RackSpace or some of the offerings from SliceHost.
rgb192Author Commented:
I think I will need to use dedicated hosting for phpmailer

or just use constant contact or mail()

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now