PHP Contact Form with Network Solutions - php

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.

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 connect and authenticate on the STMP server

I need to connect to the GMAIL SMTP server with email and password, without sending email and then receiving 200 OK.
I using the code PHPMailer:
$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 = "myuser#gmail.com";
$mail->Password = "password";
$mail->SetFrom("");
$mail->Subject = utf8_decode("My subject");
$mail->Body = "hello";
$mail->AddAddress("destination#gmail.com");
$mail->Body = template('emails/reset-password', compact('comentario'));
if ($mail->Send()) {
$mail->ClearAllRecipients();
$mail->ClearAttachments();
}
My script is sending email, I would just like to validate the authentication.
PHPMailer itself isn't much use for this as it's all about the sending. However, the SMTP class that's part of PHPMailer can do this just fine, and there is a script provided with PHPMailer that does exactly as you ask. I'm not going to reproduce the script here as it just creates maintenance for me!
The script connects to an SMTP server, starts TLS, and authenticates, and that's all.

How to resolve SMTP could not connect error? [post STARTTLS problem]

I have installed php mailer using composer composer require phpmailer/phpmailer. I followed instructions from this website https://www.geeksforgeeks.org/how-to-send-an-email-using-phpmailer.
Below is my code for sending email.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'mail.example.in';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('owner#gmail.com', 'Owner');
$mail->addAddress('receipent#gmail.com');
$mail->isHTML(true);
$mail->Subject = "Hello this is subject";
$mail->Body = "Hello this is message;
$mail->send();
echo "Mail has been sent successfully!";
}
catch (Exception $e)
{
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
When I comment $mail->isSMTP(); and send mail, I get the result as message sent but I dont get it in my Gmail inbox.
when I uncomment $mail->isSMTP(); I get error message as shown in below image.
My project is hosted in godaddy server.
Even if I use php mail() function to send mail, response is mail send successfully, but it does not get delivered into my Gmail inbox
If you want to use Gmail, you should follow the steps here to manually add Google MX records to your GoDaddy account:
https://uk.godaddy.com/help/point-my-domains-email-service-to-google-7936
Unfortunately it takes some days for changes to be reflected.
Then you need to disable security features, change your php mailer config like:
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
Hope this solves.
------EDIT------
Later I figured out that the emails go to spam folder when the port is 25. I changed the connection to TLS and now I receive them as normal.
Here is the code from my website, it works on Godaddy, I receive e-mails to my gmail account.
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'true';
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "********#gmail.com";
$mail->Password = "**********";
$mail->SetFrom("********#gmail.com");
$mail->AddAddress("********#gmail.com");
$mail->Subject = " your subject";
$mail->Body = "your body";

Yii phpmailer not working for gmail

I'm using Yii phpmailer extension to send mail using gmail but it showing SMTP Error: Could not authenticate. instead of sending mail. My code what I used
Yii::import('application.extensions.phpmailer.JPhpMailer');
$mail = new JPhpMailer;
$mail->IsSMTP();
//$mail->Host = 'smpt.163.com';
$mail->Host = 'smtp.googlemail.com:465';
//$mail->Host = 'smtp.gmail.com:587';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = $email;
$mail->Password = $pass;
$mail->SetFrom($email, SiteConfig::SITE_TITLE);
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress($email, 'My Name');
$mail->Send();
I followed this link.
How can I solve this problem and send mail using gmail? I’d appreciate any light you can shed on this!!
Try adding the following line:
$mail->Port = 465;
I am unsure if adding :port works for the Host field as you've done - I can confirm that setting the Port field manually does work, as I have a large system whose code looks very similar to yours which is working as expected.
We also use $mail->Host = 'smtp.gmail.com' but I am almost certain that the smtp.googlemail.com domain should also work.
You can debug and get error report
for 1 error and message
for 2 message only
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
Be sure to set the following attributes:
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = "your username";
$mail->Password = "your password";
It should work with those attributes set.
Hope it helps.

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