how to send smtp mail from localhost

前端 未结 2 1641
太阳男子
太阳男子 2021-01-12 06:10

I always get this message when trying to send email from my local host.

SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Er

相关标签:
2条回答
  • 2021-01-12 06:15
    1. Open the php.ini. For XAMPP, it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMP or LAMP server.
      Note: Make a backup of php.ini file.

    2. Search [mail function] in the php.ini file.

      You can find like below.
      [mail function]
      ; For Win32 only.
      ; http://php.net/smtp
      SMTP = localhost
      ; http://php.net/smtp-port
      smtp_port = 25
      
      ; For Win32 only.
      ; http://php.net/sendmail-from
      ;sendmail_from = postmaster@localhost
      

      Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25. Change sendmail_from from postmaster@localhost to your domain email address which will be used as from address.

      So for me, it will become like this.

      [mail function]
      ; For Win32 only.
      SMTP = smtp.example.com
      smtp_port = 25
      ; For Win32 only.
      sendmail_from = info@example.com
      
    3. Restart the XAMPP or WAMP(apache server) so that changes will start working.

    4. Now try to send the mail using the mail() function.

      mail("example@example.com","Success","Great, Localhost Mail works");
      

    Mail will be sent to example@example.com from the localhost with Subject line "Success" and body "Great, Localhost Mail works".

    0 讨论(0)
  • 2021-01-12 06:25

    You can add this line
    $mail->SMTPSecure = "ssl";

    after

    $mail->SMTPAuth = true;
    
    0 讨论(0)
提交回复
热议问题