Send emails via msmtp locally in php

Source: Internet
Author: User
In php, send emails locally via msmtp. refer to the http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmai. in php, send emails locally via msmtp.

See the http://www.absolutelytech.com/2010/07/18/howto-send-emailsusing-mail-function-from-localhost-in-php-through-msmtp-using-gmail-account-on-linux? Steps:

?

?

Step by step instructions:

?

  1. First of all, follow this tutorial:
    Install msmtp on your linux box and configure it to work with Gmail.

    ?

    Msmtp is highly writable able and you can easily configure it to work with any smtp server. If you want to use any other service with msmtp, you may? Read its manual? And configure it.
    Proceed to next step only if you have successfully configured and are able to send a test message.

  2. Open php. ini in your text editor.
    sudo gedit /etc/php5/apache2/php.ini

    Search for 'sendmail _ path' and change it to look like

    sendmail_path = '/usr/bin/msmtp -t'

    Save the file and exit the text editor.
    Please note that your msmtp path may vary if you are not using Ubuntu. You may find the path to executable:

    which msmtp
  3. Restart apache:

    ?

    sudo /etc/init.d/apache2 restart

    OR

    sudo /opt/lampp/lampp restart
  4. Everything's done. Lets test if the mail () function is working now:
    if ( mail ( 'yourusername@gmail.com', 'Test mail from localhost', 'Working Fine.' ) );echo 'Mail sent';elseecho 'Error. Please check error log.';

    Replace the yourusername@gmail.com with your own username, save it into a php file along with php delimeters in your virtual host root folder and execute it through the browser. You showould receive a mail.

    Similar to the above steps.

    Msmtp can be installed in apt-get install msmtp in ubuntu. after the installation, check msmtp -- ver:

    ......

    ?

    System configuration file name:/etc/msmtprc

    User configuration file name:/root/. msmtprc

    Obviously, you must ensure that the/etc/msmtprc file is available and set its configuration content. My/etc/msmtprc content is as follows: # Set default values for all following accounts. defaults
    Logfile/usr/local/msmtp. log # The SMTP server of the provider. account test
    # SMTP mail server address host smtp.ym.163.com
    # Send the email Emailfrom yanghf@kopere.comauth login
    # Mail server login account user yanghf@xxx.com # mail server login password 12345678 # Set a default accountaccount default: test
    However, when I open the test php above, an Error occurs at the beginning. please check error log. failed to send the email. check apache's error_log and find the error message: msmtp:/etc/msmtprc: must be owned by you.
    It turns out that the permission of/etc/msmtprc is 777, but it does not work and requires restrictions. Ps aux | grep httpd: check that the username of the apache process is www. Then: chown www. www/etc/msmtprc chmod 600/etc/msmtprc #600 instead of 777! Done! Then configure in mantis? $ G_phpMailer_method? ? ? ? ? ? = PHPMAILER_METHOD_MAIL is much faster than configuring PHPMAILER_METHOD_SMTP to send emails. you can receive emails immediately!

    ?

?

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.