Firehawk2047 posted on 2011-04-22 20:29:30 #
Hello,
I have followed this tutorial: http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/ and I stumbled across a problem.
My code:
require_once('phpmailer/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
define('GUSER', 'armamortala3@gmail.com'); // Gmail username
define('GPWD', 'magareata'); // Gmail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // 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;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
smtpmailer('armamortala3@gmail.com', '', 'armamortala3@gmail.com', 'yourName', 'test mail message', 'Hello World!');
I have tried time and time again to implement the PHP Mailer on my PC. I don`t understand why it does not work because I have tested the script at school and it worked fine in Wamp.
My problem: " SMTP Error: Could not authenticate. SMTP Error: Could not authenticate. Mail error: SMTP Error: Could not authenticate. "
In the code I have provided the actual password and account name in good faith.
I`m in desperate need of an solution. Help is much apreciated
The most popular forum posts:
Comments / discussions
Olaf posted on 2011-04-23 06:18:22 #
Hi,
maybe the port is not allowed or Google has blocked the server's IP?
What kind of information do you get if you use this debugging feature?
$mail->SMTPDebug = 0;
(use option 1)
Firehawk2047 posted on 2011-04-25 15:31:56 #
Hello,
First of all I would like to thank you for your reply.
I used the debugging feature and it sais:
"
Invalid address: SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (61291936)
SMTP Error: Could not connect to SMTP host.
" on option 1 and the same on option 2
What should I do ?
Olaf posted on 2011-04-25 20:07:26 #
According this message SSL is not installed on that server or at least SSL doesn't work with php.
Maybe you can use some other smtp / mail account for that script?
Firehawk2047 posted on 2011-04-26 07:59:03 #
Well, I tried three different Google mail adresses, despite that I still did not manage to connect to the server.
Considering the fact that you wrote the How-to-use tutorial, I wondered if you changed one of the settings in Gmail before running the script.
I`m puzzeled for not being able to solve this, how should I proceed from this point on ?
Olaf posted on 2011-04-26 08:23:14 #
Hi,
you didn't understood my previous answer ;) (or maybe my answer wasn't clear enough, lol)
It's not because of your gmail account(s), it's your web server configuration.
My suggestion was to use a "regular" SMTP account on port 25 without using SSL
Firehawk2047 posted on 2011-04-26 11:18:22 #
Hello,
I think I understand what you are saying. Do you mean I should connect to Google using SMRPAuth on port 25, like this:
"
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.google.com"; // sets the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "filelist.server@gmail.com"; // SMTP account username
$mail->Password = "XXXXXXXXX"; // SMTP account password
"
it says: "SMTP -> ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. "
I`m sorry, I seem to be a slow learner regarding these procedures. :(
Firehawk2047 posted on 2011-04-26 11:36:48 #
An uptate:
I also tried to use Swift with:
"
<?php
require_once 'Swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25)
->setUsername('filelist.server@gmail.com')
->setPassword('XXXXXX');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('filelist.server@gmail.com' => 'Your Name'))
->setTo(array('filelist.server@gmail.com' => 'Your friend'))
->setBody('This is the text of the mail send by Swift using SMTP transport.');
//$attachment = Swift_Attachment::newInstance(file_get_contents('path/logo.png'), 'logo.png');
//$message->attach($attachment);
$numSent = $mailer->send($message);
printf("Sent %d messages\n", $numSent);
?>
"
And I got the error:
"
Fatal error: Uncaught exception 'Swift_TransportException' with message ' in F:\SJ\wamp\www\Swift-4.0.6\Swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php on line 406
( ! ) Swift_TransportException: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. ed10sm3783766wbb.66 " in F:\SJ\wamp\www\Swift-4.0.6\Swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php on line 406
Call Stack
# Time Memory Function Location
1 0.0009 676136 {main}( ) ..\run.php:0
2 0.0765 3520512 Swift_Mailer->send( ) ..\run.php:16
3 0.2520 3572600 Swift_Transport_AbstractSmtpTransport->send( ) ..\Mailer.php:77
"
In localhost and
"
Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.gmail.com:25 (Connection timed out) in /home/a1781434/public_html/Swift/Swift/lib/classes/Swift/Transport/StreamBuffer.php on line 233
Free Web Hosting
PHP Error Message
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.gmail.com [Connection timed out #110]' in /home/a1781434/public_html/Swift/Swift/lib/classes/Swift/Transport/StreamBuffer.php:235 Stack trace: #0 /home/a1781434/public_html/Swift/Swift/lib/classes/Swift/Transport/StreamBuffer.php(70): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/a1781434/public_html/Swift/Swift/lib/classes/Swift/Transport/AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/a1781434/public_html/Swift/Swift/lib/classes/Swift/Mailer.php(74): Swift_Transport_AbstractSmtpTransport->start() #3 /home/a1781434/public_html/Swift/run.php(16): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in /home/a1781434/public_html/Swift/Swift/lib/classes/Swift/Transport/StreamBuffer.php on line 235
"
On the server
Olaf posted on 2011-04-26 12:34:24 #
Forget Google, because your server doesn't provide SSL.
You need some other e-mail provider, try the SMTP accpunt from your hosting provider.
Firehawk2047 posted on 2011-04-26 16:13:52 #
I managed to resolve the problem, it seems I needed to change a line in my php.ini file in order to work in localhost and as for the server. 000Webhost was kind enought to explain that for free hosting accounts I should upgrade for the SSL support.
In order to make it work on the server I used the simple mail() function because I didn't required to upload an attachement, however I will use localhost in order to send more complex HTML messages in the future.
Once again thanks for the support.
Olaf posted on 2011-04-26 18:06:38 #
Hi,
great that I works for you, if you need to send attachments you can use phpmailer as well, just use the isMail operator (you can find examples in the phpmailer documentation)