I tried to use SMTP with google and yahoo..even uploading the script to a host and not using smtp..and also running the script on my local machine.
Here is the script:
require_once './PHPMailer-master/class.phpmailer.php';
require_once './PHPMailer-master/class.smtp.php';
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'alforce@gmail.com'; // SMTP username
$mail->Password = '?q$';
$mail->Port= 465;
$mail->SMTPDebug=1;
// SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Timeout=350;
$mail->From = 'alforce@gmail.com';
$mail->FromName = 'alforce';
$mail->addAddress('infkot@clnt.co.il', 'Clgent'); // Add a recipient
// Set word wrap to 50 characters
$mail->addAttachment('nbproject.rar'); // Add attachments
$mail->Subject = 'Spdddd';
$mail->Body = 'Dsdssdds';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
I get this:
SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed
What am I doing wrong?
UPDATE ..it has worked. I reduced the attachment size and played with the parameters..I changed the tls to ssl.
Now when I put the code in a loop I get this errors:
Warning: fwrite(): SSL: The operation completed successfully. in C:\xampp\htdocs\PHPMailer\PHPMailer-master\class.smtp.php on line 803
and at the end I get 3 more message of this before the script dies
Warning: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry in C:\xampp\htdocs\PHPMailer\PHPMailer-master\class.smtp.php on line 803
Why?