The phpmailer mail sending function tested on the local machine is correct. the local machine is in the windowsapachephp environment, but the message Msg: stream_socket_enab appears when you send emails in linux.
The phpmailer mail sending function tested on the local machine is correct. the local machine is in the windows apache php environment, but the message Msg: stream_socket_enable_crypto () is displayed when an email is sent in linux (): this stream does not support SSL/crypto error. after analyzing N for a long time, I will share it with you.
My PHPMailer email sending code
- Header ("Content-type: text/html; charset = utf-8 ");
- Include ('phpmailer/class. phpmailer. php ');
- Include ('phpmailer/class. smtp. php ');
-
- $ Mail = new PHPMailer ();
- $ Mail-> IsSMTP (); // set mailer to use SMTP
- $ Mail-> Host = "smtp.sohu.com"; // SMTP server
- $ Mail-> Port = 25;
- $ Mail-> SMTPAuth = true; // SMTP Authentication?
- $ Mail-> Username = "yourmail@sohu.com"; // User name
- $ Mail-> Password = "yourmail168"; // Password
- $ Mail-> From = "spr_zsql@163.com"; // sender address
- $ Mail-> FromName = "test"; // sender
- $ Mail-> AddAddress ("yourmail@qq.com", "test"); // recipient address, recipient name
- $ Mail-> WordWrap = 50 ;//
- // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // attachment
- // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg"); // attachment, new file name
- $ Mail-> IsHTML (true); // HTML format
- $ Mail-> Subject = "test ";
- $ Mail-> Body = "test ";
- If (! $ Mail-> Send ())
- {
- Echo "Mailer Error:". $ mail-> ErrorInfo;
- Echo "an error occurred while sending the email! ";
- } Else {
- Echo "email sent successfully! ";
- }
When you use PHPMailer to send an email, the following error occurs: Msg: stream_socket_enable_crypto (): this stream does not support SSL/crypto. in this case, output phpinfo () and check that the openssl extension is not installed, find the location of the source code package for php installation in the/usr/local/src/php/php-5.3 example, the code is as follows:
Cd/usr/local/src/php/php-5.3/ext/openssl
/Usr/local/php/bin/phpize
The following error may occur:
Cannot find config. m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module
The code is as follows:
Mv config0.m4 config. m4
/Usr/local/php/bin/phpize
./Configure -- with-openssl -- with-php-config =/usr/local/php/bin/php-config
After make & make install is successfully installed, the following prompt will be displayed:
Build complete.
Don't forget to run 'Make test '.
Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
/Usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/Change Directory back to generate an openssl. so file, find the php configuration file, add the following code in the extension area:
Extension =/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/openssl. so
Ps-ef | grep php-fpm | grep-v grep | awk '{print $2}' | xargs kill-9
/Usr/local/php/sbin/php-fpm
If you cannot send emails after configuration, you can use the mail function in linux to directly send emails.