SMTPError: CouldnotconnecttoSMTPhost
Function sendmail ($ setEmail, $ setName, $ body, $ subject) {require_once ("PHPMail/phpmailer. php "); $ mail = new PHPMailer (true); // the true param means it will throw throtions on errors, which we need to catch $ mail-> IsSMTP (); // telling the class to use SMTPtry {$ mail-> SMTPAuth = true; // enable SMTP authentication $ mail-> SMTPSecure = SBT_SSL; // sets the prefix to the servier $ mail-> Host = SBT_SMTP _ HOST; // sets GMAIL as the SMTP server $ mail-> Port = SBT_SMTP_PORT; // set the SMTP port for the GMAIL server $ mail-> Username = SBT_SMTP_USER; // GMAIL username $ mail-> Password = SBT_SMTP_PASS; // GMAIL password $ mail-> AddReplyTo (SBT_MAIL_FROM, SBT_MAIL_FROM_NAME); $ mail-> AddAddress ($ setEmail, $ setName ); $ mail-> SetFrom (SBT_SMTP_USER, SBT_SMTP_USER); // sender name $ mail-> Subject = $ subject; $ mail-> M SgHTML ($ body); if (! $ Mail-> Send () {// (no error is reported here) echo "Message cocould not be sent."; Echo" Mailer Error :". $ mail-> ErrorInfo; exit () ;}} catch (phpmailerException $ e) {echo $ e-> errorMessage (); // Pretty error messages from PHPMailer (the output here is incorrect)} catch (Exception $ e) {echo $ e-> getMessage (); // Boring error messages from anything else !}}
Ask why, in order to use linux to schedule tasks to execute this php file
Reply to discussion (solution)
I use a gmail mailbox, 465
$mail->Host ="smtp.gmail.com"; $mail->Port =465
What about the error code?
SMTP Error: cocould not connect to SMTP host. The problem is
I don't know if I can upload the file. I'll try it out. [img = Upload
This time!
It is estimated that it is an extension problem. this extension problem will occur in the command line.
Is opensll extended? Well, you should open it. if you do not open it, the webpage will not be sent successfully.
Are you sure this file can run independently?
After testing, the webpage is easy to use and the command line is not easy to use. the error message is: extension php_pdo_mysql.dll cannot be found.
Of course, it can be run independently. I don't have to post all the code. if I don't send emails and output some text, there is no problem.
Expanded my
Php -- ini: Check whether the ini is consistent with the php running as the apache module.
I cannot install a linux environment to test it!
I can tell from the Internet that this problem is php. ini is not properly configured. I have read it and it is configured with SMTP. it is useless to change it as they said. The key is that my SMTP has been assigned a value again and the server using the Gmail mailbox is ready.
This problem does not occur on linux.
Php -- ini: Check whether the ini is consistent with the php running as the apache module.
Tiger Head, can you elaborate on modifying the INI file? Are you sure you want to do this?
[mail function]; For Win32 only.SMTP = localhostsmtp_port = 25; For Win32 only.sendmail_from = me@example.com; For Unix only. You may supply arguments as well (default: "sendmail -t -i").;sendmail_path = "/usr/sbin/sendmail -t -i"; Force the addition of the specified parameters to be passed as extra parameters; to the sendmail binary. These parameters will always replace the value of; the 5th parameter to mail(), even in safe mode.;mail.force_extra_parameters =
Reference the reply from foolbirdflyfirst on the 11 th floor:
Php -- ini: Check whether the ini is consistent with the php running as the apache module.
Tiger Head, can you elaborate on modifying the INI file? Are you sure you want to do this?
PHP code
[Mail function]
; For Win32 only.
SMTP = localhost
Smtp_port = 25
; For Win32 ......
Well, I didn't make it clear. I am talking about the php -- ini command. check whether the php running in the cli and the php running in the apache module share an ini file.
Sometimes, if phpcli is installed separately, an INI file is provided.
This problem does not occur on linux.
Eldest brother, are you familiar with linux? So I asked require_once ("PHPMail/phpmailer. php") like this; can I load phpmailer? I'm afraid linux does not accept the phpmailer plug-in
Tiger Head, please help me look at it!
C:\wamp\bin\php\php5.2.6>php --iniConfiguration FILE (php.ini) Path: C:\WINDOWSLoaded Configuration FILE: C:\wamp\bin\php\php5.2.6\php.iniScan FOR additional .ini files IN: (NONE)Additional .ini files parsed: (NONE)
IMPOSSIBLE. $ mail-> IsSMTP (); this indicates that you have set smtp sending.
Your main problem now is to find out why the socket cannot connect to the smtp server.
Firewall is also possible.
Tiger Head, you are right. they are inconsistent. why?
Loaded Configuration FILE: C: \ wamp \ bin \ php \ php5.2.6 \ php. ini
This php. ini is not the PHP. INI that I am currently running.
The wamp environment should share an INI file. if you want to confirm again, the php webpage outputs phpinfo () to check whether the INI file is consistent with this one.
Command: telnet smtp.gmail.com 465. Are you sure the connection is successful?
Tiger Head, you are right. they are inconsistent. why?
Good
Use the php-c command to introduce your correct ini path.
Php-c ini path php file
You can view the command parameters in php-help.
Learning onlookers
Check the firewall, and then check the code that sends the image attachment.
The wamp environment should share an INI file. if you want to confirm again, the php webpage outputs phpinfo () to check whether the INI file is consistent with this one.
Command: telnet smtp.gmail.com 465. Are you sure the connection is successful?
Telnet smtp.gmail.com 465 cannot be connected. what mail server should I use?
Telnet does not work. it must have been disabled by your firewall.
Thank you for solving the problem. The first is the firewall problem. The third is the failure of the 360 firewall, and the second is the ini problem.
To RXPY2007
Php. ini, please make it clear. I also encountered this problem, linux environment
I hope the landlord can clarify how to solve the problem. my win environment also encountered a problem.
!
Is gmail registered with the Enterprise edition?
[Quote = reference the reply from rxpy2007 on the 14th floor:]
Reference the reply from foolbirdflyfirst on the 11 th floor:
Php -- ini: Check whether the ini is consistent with the php running as the apache module.
Tiger Head, can you elaborate on modifying the INI file? Are you sure you want to do this?
PHP code
[Mail function]
; For Win32 only.
SMTP = localhost
Smtp_port = 25
; For Win32 ......
Well, I didn't make it clear. I am talking about the php -- ini command. check whether the php running in the cli and the php running in the apache module share an ini file.
Sometimes, if phpcli is installed separately, an INI file is provided.
How can I use php -- ini?