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

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)

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;

mail not send via SMTP API using sendgrid

Mail not send to user via SMTP using sendgrid.it shows SMTP error
code
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.sendgrid.net"; // SMTP server
$mail->SMTPSecure = "SSL";
$mail->SMTPAuth = true;
$mail->Username = "szdfsdf";
$mail->Password = "sdfsdfsdfsdf";
$mail->Port = "465";
$mail->From = "tests#gmail.com";
$mail->FromName = "Test";
$mail->AddAddress("test#services.in");
$message = "hi how r u in medapps?";
$message = trim($message);
$mail->Subject = "from test";
$mail->Body = trim($message);
if(!$mail->Send()){
echo "Mailer error: ".$mail->ErrorInfo;
}
else{
echo "Mail triggered to alert the status!";
}
result
Mailer error: SMTP Error: Could not connect to SMTP host.
When connecting to SendGrid via SMTP using API Keys, you need to use apikey as the username.
Also, since you just shared that API Key publicly here, you need to destroy it and make a new one. It's no longer secure.
SendGrid does support port 465 for SSL connectiong, but as Jim said, you need to test your connection and see if your server is allowing that connection. If not, try a different port as recommended on that article.
I would recommend trying port 587 with a TLS connection.

PHPMailer- Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting?

I'm trying to use the phpmailer in my project, but the SMTP settings for gmail doesn't seem to be right. I referred a few questions asked here before, but none of the solutions seem to work for me.
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = ''; //gmail address
$mail->Password = ''; // gmail password
$mail->From = 'user#domain.com';
$mail->FromName = 'John Doe';
$mail->AddAddress('yadayada#gmail.com', 'Nick'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'subject';
$mail->Body = 'message body';
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('images/apache_pb.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
You must to have installed php_openssl.dll, if you use wampserver it's pretty easy, search and apply the extension for PHP.
In the example change this:
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 465 ssl
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
and then you recived an email from gmail talking about to enable the option to Less Safe Access Applications here https://www.google.com/settings/security/lesssecureapps
use
$mail->Host = 'mail.servce.com';

SMTP Gmail Server SSL Error

I used this coding to send mail using gmail, but am getting the below error, here when i removed the ssl part, its working, but i dint receive any emails(checked inside spam also). Any other problems ?
$mail = new phpmailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1;// enables SMTP debug information (for testing)
$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 = "un"; // GMAIL username
$mail->Password = "pwd"; // GMAIL password
$mail->SetFrom('test#gmail.com', 'Bharanidharan');
$mail->AddReplyTo("test#gmail.com","Vishal Kumar");
$mail->AddAddress("test#gmail.com","Bharani");
$mail->Subject = "Hey, check out";
$body = "hey, check email";
$mail->MsgHTML($body);
$address = "test#gmail.com";
$mail->AddAddress($address, "test");
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
Enable the mod_ssl in Apache (search the config file) and the openssl PHP extension (check php.ini)

SMTP Error: Could not connect to SMTP host

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";
}

Categories