Message could not be sent.Mailer Error: SMTP connect() failed
Just for sake of other that use az.pl here is changed script that works (without tls and with commented out $mail->isSMTP();)
<?php
$name = $_POST['nick'];
$visitor_email = $_POST['email'];
$visitor_tel = $_POST['tel'];
$message = $_POST['msg'];
require 'PHPMailerAutoload.php';
require_once('class.phpmailer.php'); // dodanie klasy phpmailer
require_once('class.smtp.php'); // dodanie klasy smtp
$mail = new PHPMailer(); //utworzenie nowej klasy phpmailer
$mail->isSMTP();
$mail->Host = "mailng.az.pl"; //adres serwera SMTP wysyłającego e-mail
$mail->Mailer = "smtp"; //do wysłania zostanie użyty serwer SMTP
$mail->SMTPAuth = true; //włączenie autoryzacji do serwera SMTP
$mail->Username = ""; //nazwa użytkownika do skrzynki e-mail
$mail->CharSet = 'UTF-8';
$mail->From = ""; //Pełny adres e-mail
$mail->FromName = "Formularz kontaktowy"; //imię i nazwisko lub nazwa użyta do wysyłania wiadomości
$mail->Password = ""; //hasło użytkownika do skrzynki e-mail
$mail->Port = 587; //port serwera SMTP
$mail->Subject = "Nowe zlecenie: $visitor_email"; //Temat wiadomości, można stosować zmienne i znaczniki HTML
$mail->Body = "Nazwa zleceniodawcy: $name \n";
$mail->Body .="Email kontaktowy: $visitor_email \n";
$mail->Body .= "Telefon kontaktowy: $visitor_tel\n";
$mail->Body .= "Zlecenie: $message"; //Treść wiadomości, można stosować zmienne i znaczniki HTML
$mail->SMTPSecure = ''; //
$mail->SMTPAutoTLS = false; //wyłączenie TLS
$mail->AddAddress ("",""); //adres skrzynki e-mail oraz nazwa
//adresata, do którego trafi wiadomość
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
header('Location: emailsent.html');
}
?>
Mailer Error SMTP connect() failed
Your code is correct except few things. I edited your code and the message get sent. Also check whether your username and password is correct or not as I tried with my username and password.And also check did you include the class.phpmailer.php.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP();
$mail->Mailer = "smtp";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true; // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mygmail@gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mymail@gmail.com', 'Mailer');
$mail->addAddress('sendtomail@gmail.com', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}
?>
SMTP connect() failed PHPmailer - PHP
You need to add the Host
parameter
$mail->Host = "ssl://smtp.gmail.com";
Also, check if you have open_ssl
enabled.
<?php
echo !extension_loaded('openssl')?"Not Available":"Available";
PHP Mailer error: Message could not be sent.Mailer Error: SMTP connect() failed
Your hosting company, one.com, blocks outgoing mail ports intentionally to restrict malicious PHP scripts. The send.one.com
address is meant for external mail clients such as your mobile phone, email client, etc. and not for internal mailing scripts from your website.
As per their support document concerning sending emails from your website, you must change the host to their internal SMTP address, mailout.one.com
- since this is an internal relay, you must also use port 25 and disable any security such as TLS or SSL. You must also disable authentication.
Here is the correct configuration:
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mailout.one.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Authentication must be disabled
$mail->Username = 'myemailhidden';
$mail->Password = ''; // Leave this blank
$mail->Port = 25; // TCP port to connect to
Related Topics
Why Is Register_Globals So Bad
Call to Undefined Function Oci_Connect()
PHP Curl, Extract an Xml Response
Best Practice Multi Language Website
How to Write to the Console in PHP
How to Make This Preg_Match Case Insensitive
Can't Access Global Variable Inside Function
How to Linkify Urls in a String With PHP
Converting a Simplexml Object to an Array
Use One Bind_Param() With Variable Number of Input Vars
MySQL_Fetch_Array, MySQL_Fetch_Assoc, MySQL_Fetch_Object
Get the Date of Next Monday, Tuesday, etc
How to Get the Real Url After File_Get_Contents If Redirection Happens
Import CSV File Directly into MySQL