I tried EVERY single script / code / method posted on StackOverflow and other sites for this, but with no luck. I go to GoDaddy. I set up a Google App account, set up everything necessary for MX records (using the GoDaddy tool for this) and even tried to send some messages from the GMAIL interface for my site, as well as via SMTP in the terminal on one of my unix machines. It all worked.
HOWEVER, when I try to use PHP, it is not! Does GoDaddy seem to be blocking it somehow?
I always get:
SMTP → ERROR: Could not connect to server: Connection refused (111) SMTP Error: Could not connect to the SMTP host. Mailer error: SMTP error: Could not connect to the SMTP host.
Here is the code I'm using for PHPMailer:
<html> <head> <title>PHPMailer - SMTP (Gmail) advanced test</title> </head> <body> <?php require_once('../class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->IsSMTP(); // telling the class to use SMTP try { $mail->Host = "smtp.gmail.com"; // SMTP server $mail->SMTPDebug = 2; // 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 = "MYFROMADDRESSHERE"; // GMAIL username $mail->Password = "MYFROMPASSWORDHERE"; // GMAIL password $mail->AddReplyTo('MYFROMADDRESSHERE', 'Sender Name'); $mail->AddAddress('TESTTOADDRESSHERE', 'Recipient Name'); $mail->SetFrom('MYFROMADDRESSHERE', 'Sender Name'); $mail->AddReplyTo('MYFROMADDRESSHERE', 'Sender Name'); $mail->Subject = 'PHPMailer Test Subject via mail(), advanced'; $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically $mail->MsgHTML(file_get_contents('contents.html')); $mail->AddAttachment('images/phpmailer.gif'); // attachment $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment $mail->Send(); echo "Message Sent OK</p>\n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } ?> </html>
Thanks!
php phpmailer smtp gmail
johnshaddad
source share