SMTP Error: Could not connect to SMTP host - php

I have this code, and all works well in my local server. The email is sent without any problem.
But now I pass the content to webserver, and I get this error...
SMTP Error: Could not connect to SMTP host.
SSL is enable in the server..correct? so, what is the problem?
$mail = new PHPMailer();
$mail->IsSMTP();
$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
$mail->Username = "dnteiro"; // GMAIL username
$mail->Password = "xxx"; // GMAIL password

It sounds like your web host is blocking outbound connections to smtp.gmail.com:465. Suggestions:
Verify: If you have shell/terminal access to your web hosting server, try a telnet test to verify that they are in fact blocking this. Run telnet smtp.gmail.com 465
Contact: Call or email your hosting provider and find out what SMTP server they provide for outbound relay. Make sure they know you want to use your #gmail.com address as the From/Reply-to address.
Update code: Once your host provides you with a different mail server, update your code and try again.
If your web host doesn't allow outbound relay from its servers at all, then you need to look at switching hosts, if this is a requirement for your application.

AJ is right in regards to #2, it is specified in:
http://support.google.com/mail/bin/answer.py?hl=en&answer=78775

require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.abc.co.in';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Username = 'user name';
$mail->Password = 'password';
$mail->setFrom("from email id", "name");
$mail->addAddress("receipiant email id");
$mail->isHTML(true);
$bodycontent = 'body';
$mail->Body = $bodycontent;
if (!$mail->send()) {
echo "message has been not send", $mail->ErrorInfo;
}
else{
echo "message has been send";
}

Related

PHPMailer works fine on localhost but not on live server [duplicate]

I've got a bizarre problem here. I'm trying to use PHPMailer to send an email, through SMTP. I have a website hosted by GoDaddy and it's that SMTP account that I'm trying to use to send the mail.
It works if I execute my PHP file on my localhost server.
It does not work if I execute my PHP file on GoDaddy's server.
The error message I get is:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
I checked phpinfo on both localhost and the remote server. Both have smtp_port listed as 25. I'm using WAMP on my machine and the server is some form of Linux (which I know nothing about and have no idea how to administer).
Here is the code in question:
INDEX.PHP:
<?php
date_default_timezone_set('America/Los_Angeles');
include_once("phpmailer/class.phpmailer.php");
$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->Port = 25;
$mail->IsSMTP();
$mail->Host = 'smtpout.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = 'username#site.com';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result
$mail->ClearAddresses();
$mail->AddAddress('receiver#hotmail.com', 'Receiver Name');
$mail->From = "username#site.com";
$mail->FromName = "Username";
$mail->Subject = 'Hi there';
$mail->Body = "This is a message";
if ($mail->Send()) {
echo "Message sent!\n";
}
else {
echo "Message failed!\n";
print_r($mail->ErrorInfo);
}
exit();
?>
I think you should perform two step
1) check your port as suggested on godaddy support http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account
2)use "relay-hosting.secureserver.net" as your host instead of "smtpout.secureserver.net"
GoDaddy does allow to send emails using Gmail as your SMTP, just need to get rid of the smtp.gmail.com and use their Host instead. This is my setup:
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account#gmail.com";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...
Reference (see first two posts) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/
If your hosting has own email server, the server will use the following ports 25,465,587.
Settings for GoDaddy:
$mail->isSMTP();
$mail->Host = localhost;
$mail->SMTPAuth = true;
$mail->Username = 'example#gmail.com';
$mail->Password = 'password';
//$mail->SMTPSecure = 'tls';
//$mail->Port = 587;
For other providers you have to create a mailbox with your domain:
$mail->isSMTP();
$mail->Host = localhost;
$mail->SMTPAuth = true;
$mail->Username = 'example#yourdomain.com';
$mail->Password = 'password';
//$mail->SMTPSecure = 'tls';
//$mail->Port = 587;

How to configure SMTP settings based on web hosting's mail account

Hello how do i configure my php mailer to make it work with these settings?
i tried to fix the username and password but i still get this error
PHPMailer Error: The following From address failed: thesis#thesis.buybranded.com.ph : Called Mail() without being connected
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'gowebph.gowebph.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
// or try these settings (worked on XAMPP and WAMP):
// $mail->Port = 465;
// $mail->SMTPSecure = 'ssl';
$mail->Username = "thesis#thesis.buybranded.com.ph";
$mail->Password = "XXXXXXXXXXXXXX";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
$mail->From = "thesis#thesis.buybranded.com.ph";
$mail->FromName = "Your Name";
$mail->addAddress("vince_agno#live.com","User 1");
$mail->addAddress("2009010067#ust-ics.mygbiz.com","User 2");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
You've got your port & protocol mismatched. port 465 is for ssl and port 587 is for tls.
see https://support.google.com/mail/answer/13287?hl=en
Could you please use this
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
also
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
Or if using TLS try to use port 587 for TLS
from wiki ---Secure SMTP - port 587 (can also use the legacy port 465 - this may solve problems with SSL) (port 587 has optional TLS encryption, possibly using STARTTLS now, or use port 465 for SSL encryption)

SMTP Error: Could not connect to SMTP host using PHPMailer

we are using SMTP advanced authentication to send a test mail using PHPMailer.
We are using 1and1.com server with SMTP and SSL for E-mail Exchange.
We need to run this php page from a third party server. we have taken a example from the downloaded PHPMailer package. we have tried with "test_pop_before_smtp_advanced" example and " SMTP advanced test with authentication" example. In both cases we are getting same Error.
SMTP Error: Could not connect to SMTP host.
Here is the php file we have written for sending Mail.
<html>
<head>
<title>PHPMailer - SMTP advanced test with authentication</title>
</head>
<body>
<?php
echo "hai";
include('class.phpmailer.php');
include('class.smtp.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
echo "hai1";
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = "smtp.1and1.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtp.1and1.com"; // sets the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "xxx#abc.com"; // SMTP account username
$mail->Password = "xxxxx"; // SMTP account password
$mail->AddReplyTo('mno#abc.com', 'First Last');
$mail->AddAddress('mno#abc.com', 'John Doe');
$mail->SetFrom('xxx#abc.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->Body = 'hello';
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
} catch (phpmailerException $e) {
echo "error";
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo "err";
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
</body>
</html>
Can anyone help us in this regard, please suggest any other easy approach for the same purpose. Thank you...
I had the same problem, and was walked through a bunch of different port, domain, and security configuration attempts. Try to use these settings, I found them on another help site and they worked for me.
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = '74.208.5.2'; // Specify main and backup SMTP server (server name)
$mail->Port = 25; // TCP port to connect to 587 or 465, 425, 25
$mail->Username = 'xxxxx#xxx.com'; // SMTP username
$mail->Password = 'xxxxxx'; // SMTP password
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
I had to set SMTPSecutre to tls or remove this line completely, use smtp.1and1.net's ip for the host (you can verify with a ping or whois), and set port to 25. Even though 1and1 suggested other ports more often. Hopefully this saves someone some time.
PHP suddenly changed in version 5.6 to be much more strict about SSL connections. This causes many web contact forms to break, often without any error message being displayed. If you want to continue using a self-signed certificate, or allowing a non-SSL (insecure) connection, a quick workaround for PHPMailer is to use:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
if you are using an SSL connection - try changing your port to default SSL port 465
If you are not using SSL, try removing these lines:
$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
and change the port to default port 25.
As you are getting a could not connect, take a moment to check your login details are correct, even the best of us can fall foul of a miss-typed password.

PHP Contact Form with Network Solutions

Have a basic contact form using https://github.com/PHPMailer/PHPMailer on a Network Solutions shared hosting package.
// start the mail request basics
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->Debugoutput = 'html';
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = 'my_gmail_account#gmail.com';
$mail->Password = '*******';
Everything works find locally (on my computer) and form sends email, but when I upload this php file to our network solutions hosting I get the following Error.
SMTP ERROR: Failed to connect to server: Connection timed out (110)
SMTP connect() failed.
Is there something wrong with my Mail Settings? Anyone else had success with PHP mailing on Network Solutions Shared Hosting?
Network Solutions blocks several ports required to send mail including those needed for gmail.
If anyone finds an alternate, please let me know.
For now, used a dummy account and used standard PHP mailer then forwarded mail.
You could change your config options like this.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->Username = "my_gmail_account#gmail.com";
$mail->Password = "********";
$mail->SetFrom("somemail#gmail.com");
$mail->Subject = "Testing the New Config";
$mail->Body = "Hey there !";
I got it to work with these settings:
$mail->SMTPOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
"allow_self_signed" => true
)
);
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
$mail->Host = "email-out-priv.myregisteredsite.com";
$mail->Port = 25;
$mail->Username = "noreply#mydomain.com";
$mail->Password = "********";
You have to pay for an email address with Network Solutions for a domain you own. You can see the host and port by logging into your mailbox (mail.mydomain.com) --> Top right Menu --> Settings --> Mail --> Mail and Social Accounts --> E-Mail (Edit) --> Outgoing server (SMTP). I used this PHP Mailer Documentation as a clue to this solution.

Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix?

I would like to send an email using Gmail SMTP server through PHP Mailer.
this is my code
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'MyUsername#gmail.com';
$mail->Password = 'valid password';
$mail->SMTPAuth = true;
$mail->From = 'MyUsername#gmail.com';
$mail->FromName = 'Mohammad Masoudian';
$mail->AddAddress('anotherValidGmail#gmail.com');
$mail->AddReplyTo('phoenixd110#gmail.com', 'Information');
$mail->IsHTML(true);
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = "Hello";
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
?>
but I receive this following error
Mailer Error: SMTP Error: The following recipients failed: anotherValidGmail#gmail.com
SMTP server error: SMTP AUTH is required for message submission on port 587
my domain is vatandesign.ir
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "email#gmail.com";
$mail->Password = "password";
$mail->SetFrom("example#gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("email#gmail.com");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
This code above has been tested and worked for me.
It could be that you needed $mail->SMTPSecure = 'ssl';
Also make sure you don't have two step verification switched on for that account as that can cause problems also.
UPDATED
You could try changing $mail->SMTP to:
$mail->SMTPSecure = 'tls';
It's worth noting that some SMTP servers block connections.
Some SMTP servers don't support SSL (or TLS) connections.
So I just solved my own "SMTP connection failure" error and I wanted to post the solution just in case it helps anyone else.
I used the EXACT code given in the PHPMailer example gmail.phps file. It worked simply while I was using MAMP and then I got the SMTP connection error once I moved it on to my personal server.
All of the Stack Overflow answers I read, and all of the troubleshooting documentation from PHPMailer said that it wasn't an issue with PHPMailer. That it was a settings issue on the server side. I tried different ports (587, 465, 25), I tried 'SSL' and 'TLS' encryption. I checked that openssl was enabled in my php.ini file. I checked that there wasn't a firewall issue. Everything checked out, and still nothing.
The solution was that I had to remove this line:
$mail->isSMTP();
Now it all works. I don't know why, but it works. The rest of my code is copied and pasted from the PHPMailer example file.
Also worth noting that if you have two factor authentication enabled, you'll need to setup an application specific password to use in place of your email account's password.
You can generate an application specific password by following these instructions:
https://support.google.com/accounts/answer/185833
Then set $mail->Password to your application specific password.
It seems that your server fails to establish a connection to Gmail SMTP server.
Here are some hints to troubleshoot this:
1) check if SSL correctly configured on your PHP (module that handle it isn't installed by default on PHP. You have to check your configuration in phph.ini).
2) check if your firewall let outgoing calls to the required port (here 465 or 587). Use telnet to do so. If the port isn't opened, you'll then require some support from sysdmin to setup the config.
I hope you'll sort this out quickly!
Google treat Gmail accounts differently depending on the available user information, probably to curb spammers.
I couldn't use SMTP until I did the phone verification. Made another account to double check and I was able to confirm it.
this code working fine for me
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 0;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = $hostname;
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = $sender;
$mail->Password = $mail_password;
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "ssl";
//Set TCP port to connect to
$mail->Port = 465;
$mail->From = $sender;
$mail->FromName = $sender_name;
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = $Subject;
$mail->Body = $Body;
$mail->AltBody = "This is the plain text version of the email content";
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo 'Mail Sent Successfully';
}
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
If you are using cPanel you should just click the wee box that allows you to send to external servers by SMTP.
Login to CPanel > Tweak Settings > All> "Restrict outgoing SMTP to
root, exim, and mailman (FKA SMTP Tweak)"
As answered here:
"Password not accepted from server: 535 Incorrect authentication data" when sending with GMail and phpMailer
Anderscc has got it correct. Thanks. It worked for me but not 100%.
I had to set
$mail->SMTPDebug = 0;
Setting it to 1, can cause errors especially if you are passing some data as json to next page. Example - Performing verification if mail is sent, using json to pass data through ajax.
I had to lower my gmail account security settings to get rid of errors:
" SMTP connect() failed " and " SMTP ERROR: Password command failed "
Solution:
This problem can be caused by either 'less secure' applications trying to use the email account (this is according to google help, not sure how they judge what is secure and what is not) OR if you are trying to login several time in a row OR if you change countries (for example use VPN, move code to different server or actually try to login from different part of the world).
Links that fix the problem (you must be logged into google account):
view recent attempts to use the account and accept suspicious access.
link to disable the feature of blocking suspicious apps/technologies:
https://www.google.com/settings/u/1/security/lesssecureapps
Note:
You can go to the following stackoverflow answer link for more detailed reference.
https://stackoverflow.com/a/25175234
I have found a solution and it is working.
Basic settings:
$mail->IsHTML(true);
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
//SMTP::DEBUG_OFF = off (for production use)
//SMTP::DEBUG_CLIENT = client messages
//SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_CLIENT;
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = 'user#gmail.com';
//Password to use for SMTP authentication
$mail->Password = 'PASSWORD_HERE';
//Set who the message is to be sent from
$mail->setFrom('email#email.ext', 'From where it is sent');
//Set an alternative reply-to address
$mail->addReplyTo('email#email.ext', 'Reply To');
//Set who the message is to be sent to
$mail->addAddress('email#email.ext');
//Set the subject line
$mail->Subject = 'Email subject';
// Body message
$mail->Body = '
<h1>Message details</h1>
';
// Send message
if( $mail->send() ) {
echo "Sent"
} else {
echo "Not Sent";
}
If you've already tried everything, try doing this:
Disable the feature of blocking suspicious apps/technologies https://www.google.com/settings/u/1/security/lesssecureapps
Clear the Captcha https://accounts.google.com/b/0/DisplayUnlockCaptcha
Do the test.
Here are some articles of interest that helped me solve this:
https://support.google.com/a/thread/108782439/smtp-error-password-command-failed-535-5-7-8-username-and-password-not-accepted?hl=en&msgid=108963583
https://bobcares.com/blog/phpmailer-smtp-error-password-command-failed/
I just wanted to share my experience with phpMailer , that was working locally (XAMPP) but wasn't working on my hosting provider.
I turned on phpMailer error reporting
$mail->SMTPDebug=2
I got 'Connection refused Error'
I email my host provider for the issue, and they said that they would open the SMTP PORTS 25, 465, 587.
Then I got the following error response "SMTP ERROR: Password command failed:"...."Please log in via your web browser and then try again"...."SMTP Error: Could not authenticate."
So google checks if your are logged in to your account (I was when I ran the script locally through my browser) and then allows you to send mail through the phpMailer script.
To fix that:
1: go to your Google account -> security
2: Scroll to the Key Icon and choose "2 way verification" and follow the procedure
3: When done go back to the key icon from google account -> security and choose the second option "create app passwords" and follow the procedure to get the password.
Now go to your phpMailer object and change your Google password with the password given from the above procedure.
You are done.
The code:
require_once('class.phpmailer.php');
$phpMailerObj= new PHPMailer();
$phpMailerObj->isSMTP();
$phpMailerObj->SMTPDebug = 0;
$phpMailerObj->Debugoutput = 'html';
$phpMailerObj->Host = 'smtp.gmail.com';
$phpMailerObj->Port = 587;
$phpMailerObj->SMTPSecure = 'tls';
$phpMailerObj->SMTPAuth = true;
$phpMailerObj->Username = "YOUR EMAIL";
$phpMailerObj->Password = "THE NEW PASSWORD FROM GOOGLE ";
$phpMailerObj->setFrom('YOUR EMAIL ADDRESS', 'THE NAME OF THE SENDER',0);
$phpMailerObj->addAddress('RECEIVER EMAIL ADDRESS', 'RECEIVER NAME');
$phpMailerObj->Subject = 'SUBJECT';
$phpMailerObj->Body ='MESSAGE';
if (!phpMailerObj->send()) {
echo "phpMailerObjer Error: " . $phpMailerObj->ErrorInfo;
return 0;
} else {
echo "Message sent!";
return 1;
}
If anyone there who is not getting a working answer, they can try this.
Note: I am using PHPMailer 5.2.23.
<?php
date_default_timezone_set('Asia/Kolkata');
require './Libraries/PHPMailer5/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
// Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'localhost';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "yourWebmailUsermail";
$mail->Password = "yourWebmailPassword";
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->setFrom('formEmailAddress', 'First Last');
$mail->addAddress('toEmailAddress', 'John Doe');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("<h1>Hi Test Mail</h1>");
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I think it is connection issue you can get code here http://skillrow.com/sending-mail-using-smtp-and-php/
include(“smtpfile.php“);
include(“saslfile.php“); // for SASL authentication $from=”my#website.com“; //from mail id
$smtp=new smtp_class;
$smtp->host_name=”www.abc.com“; // name of host
$smtp->host_port=25;//port of host
$smtp->timeout=10;
$smtp->data_timeout=0;
$smtp->debug=1;
$smtp->html_debug=1;
$smtp->pop3_auth_host=””;
$smtp->ssl=0;
$smtp->start_tls=0;
$smtp->localhost=”localhost“;
$smtp->direct_delivery=0;
$smtp->user=”smtp username”;
$smtp->realm=””;
$smtp->password=”smtp password“;
$smtp->workstation=””;
$smtp->authentication_mechanism=””;
$mail=$smtp->SendMessage($from,array($to),array(“From:$from”,”To: $to”,”Subject: $subject”,”Date: ”.strftime(“%a, %d %b %Y %H:%M:%S %Z”)),”$message”);
if($mail){
echo “Mail sent“;
}else{
echo $smtp->error;
}

Categories