When PHPMailer sends an email, the following error occurs: Msg: stream_socket_enable_crypto ():

Source: Internet
Author: User
Tags apache php zts
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

  1. Header ("Content-type: text/html; charset = utf-8 ");
  2. Include ('phpmailer/class. phpmailer. php ');
  3. Include ('phpmailer/class. smtp. php ');
  4.  
  5. $ Mail = new PHPMailer ();
  6. $ Mail-> IsSMTP (); // set mailer to use SMTP
  7. $ Mail-> Host = "smtp.sohu.com"; // SMTP server
  8. $ Mail-> Port = 25;
  9. $ Mail-> SMTPAuth = true; // SMTP Authentication?
  10. $ Mail-> Username = "yourmail@sohu.com"; // User name
  11. $ Mail-> Password = "yourmail168"; // Password
  12. $ Mail-> From = "spr_zsql@163.com"; // sender address
  13. $ Mail-> FromName = "test"; // sender
  14. $ Mail-> AddAddress ("yourmail@qq.com", "test"); // recipient address, recipient name
  15. $ Mail-> WordWrap = 50 ;//
  16. // $ Mail-> AddAttachment ("/var/tmp/file.tar.gz"); // attachment
  17. // $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg"); // attachment, new file name
  18. $ Mail-> IsHTML (true); // HTML format
  19. $ Mail-> Subject = "test ";
  20. $ Mail-> Body = "test ";
  21. If (! $ Mail-> Send ())
  22. {
  23. Echo "Mailer Error:". $ mail-> ErrorInfo;
  24. Echo "an error occurred while sending the email! ";
  25. } Else {
  26. Echo "email sent successfully! ";
  27. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.