I looked at the following links:
phpmailer send gmail smtp timeout
send emails using the Gmail SMTP server via PHP Mailer
http://uly.me/phpmailer-and-gmail-smtp/
... and tried to realize a combination of them for himself, however ... most of the time he sends this message ...
Message could not be sent.Mailer Error: SMTP connect () Error.
Message could not be sent.
Mailer Error: SMTP connect () Error.
However, there was one time when he posted this, when I experimented between "tls" and "ssl" ...
SMTP ERROR: Could not connect to server: connection timeout (110) SMTP connect () error. Message could not be sent.Mailer Error: SMTP connect () Error.
SMTP ERROR: Could not connect to server: connection timeout (110) SMTP connect () error. Message could not be sent.
... - -? -, - , SMTP Gmail.
require_once("class.phpmailer.php"); $mail = new PHPMailer(); $mail -> IsSMTP(); $mail -> SMTPDebug = 2; $mail -> SMTPAuth = 'true'; $mail -> SMTPSecure = 'tls'; $mail -> SMTPKeepAlive = true; $mail -> Host = 'smtp.gmail.com'; $mail -> Port = 587; $mail -> IsHTML(true); $mail -> Username = "myemail@gmail.com"; $mail -> Password = "mypassword"; $mail -> SingleTo = true; $to = xxx; $from = xxx; $fromname = xxx; $subject = xxx; $message = xxx $headers = "From: $from\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $mail -> From = $from; $mail -> FromName = $fromname; $mail -> AddAddress($to); $mail -> Subject = $subject; $mail -> Body = $message; if(!$mail -> Send()){ echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail-> ErrorInfo; exit; }
. fsocketopen, php, . php :
$host = "smtp.gmail.com"; $port = "587"; $checkconn = fsockopen($host, $port, $errno, $errstr, 5); if(!$checkconn){ echo "($errno) $errstr"; } else { echo 'ok'; }
"". , , Phpmailer. , , , . , , , - , php.
, script
:
SMTP- phpmailer:
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
phpmailer. SMTP . -, -.
gmail. Gmail .
smtp . :
ssl
$mail -> SMTPSecure = 'ssl';
465
$mail -> Port = 465;
$mail -> Host = 'ssl://smtp.gmail.com';
,
, gmail -. , Linux. SSH
telnet smtp.gmail.com 587
Connected to smtp.something
localhost .
, :
, Gmail .
, .
.
date_default_timezone_set('Etc/UTC');
. SMTP , .
, , .
sendmail Windows http://www.glob.com.au/sendmail/sendmail.zip sendmail.exe sendmail.ini C:/usr/lib/
sendmail.ini .
, 2 ( ) force_sender=you-sender@yourdomain.com force_recipient=you@yourdomain.com , debug_logfile, , SMTP-.
c:\php\php.ini
sendmail_from = you@yourdomain.com
; Unix. ( : "sendmail -t -i" ). sendmail_path = C:/usr/lib/sendmail.exe -t -i
apache sendmail.exe [] > > C:/usr/lib/sendmail.exe C:/usr/lib Windows, DoubleClick exe .
Sendmail Wamp Php
Windows 10 gmail
CMD sendmail /,
sc create SendMail binpath= "C:\usr\lib\sendmail.exe"
, OpenSSL, : https://slproweb.com/products/Win32OpenSSL.html
, , " Windows". , .