I'm getting error SMTP connect() failed phpmailer with localhost:
2015-09-10 09:34:48 Connection: opening to ssl://smtp.gmail.com:587, timeout=300, options=array ( ) 2015-09-10 09:34:48 SMTP ERROR: Failed to connect to server: (0) 2015-09-10 09:34:48 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
- Is it phpmailer cannot run at localhost?
- If I want really run at localhost how can I change the code?
- I tried using mailto function is work for me but I want change whole thing.
can give any suggestion. I really want to learn it.
This is the code from github: require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer; //$mail->SMTPDebug = 4; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'mygmailpassword'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to //$mail->Host = 'tls://smtp.gmail.com:587'; $mail->From = '[email protected]'; $mail->FromName = 'Mailer'; $mail->addAddress('[email protected]', 'Joe User'); // Add a recipient $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; }