Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

phpmailer and gmail

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


$mail = new PHPMailer(true);

try {
  $mail->IsHTML(true);
  
  
  
$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->AddAddress($mail->Username);
  $mail->Body = 'body';
   
  $mail->Subject="subject";

  
  $mail->Send();
  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.
ASKER CERTIFIED SOLUTION
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

I think I will need to use dedicated hosting for phpmailer

or just use constant contact or mail()