Send email from localhost running XAMMP in PHP using GMAIL mail server

后端 未结 5 1680
[愿得一人]
[愿得一人] 2020-11-22 11:21

I try to send an email from localhost to my yahoo email account using php mail() function, the return says I successfully send the email but I did not get any email. I\'ve b

相关标签:
5条回答
  • 2020-11-22 12:09

    Here's the link that gives me the answer:

    [Install] the "fake sendmail for windows". If you are not using XAMPP you can download it here: http://glob.com.au/sendmail/sendmail.zip

    [Modify] the php.ini file to use it (commented out the other lines):
    
    [mail function]
    ; For Win32 only.
    ; SMTP = smtp.gmail.com
    ; smtp_port = 25
    
    ; For Win32 only.
    ; sendmail_from = <e-mail username>@gmail.com
    
    ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
    sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
    

    (ignore the "Unix only" bit, since we actually are using sendmail)

    You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:

    [sendmail]
    
    smtp_server=smtp.gmail.com
    smtp_port=25
    error_logfile=error.log
    debug_logfile=debug.log
    auth_username=<username>
    auth_password=<password>
    force_sender=<e-mail username>@gmail.com
    

    To access a Gmail account protected by 2-factor verification, you will need to create an application-specific password. (source)

    0 讨论(0)
  • 2020-11-22 12:11

    Don't forget to generate a second password for your Gmail account. You will use this new password in your code. Read this:

    https://support.google.com/accounts/answer/185833

    Under the section "How to generate an App password" click on "App passwords", then under "Select app" choose "Mail", select your device and click "Generate". Your second password will be printed on the screen.

    0 讨论(0)
  • 2020-11-22 12:12

    Simplest way is to use PHPMailer and Gmail SMTP. The configuration would be like the below.

    require 'PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    
    $mail->isSMTP();                            
    $mail->Host = 'smtp.gmail.com';            
    $mail->SMTPAuth = true;                     
    $mail->Username = 'Email Address';          
    $mail->Password = 'Email Account Password'; 
    $mail->SMTPSecure = 'tls';               
    $mail->Port = 587;                  
    

    Example script and full source code can be found from here - How to Send Email from Localhost in PHP

    0 讨论(0)
  • 2020-11-22 12:13
    [sendmail]
    
    smtp_server=smtp.gmail.com  
    smtp_port=25  
    error_logfile=error.log  
    debug_logfile=debug.log  
    auth_username=myemail@gmail.com 
    auth_password=gmailpassword  
    force_sender=myemail@gmail.com
    

    need authenticate username and password of mail then only once can successfully send mail from localhost

    0 讨论(0)
  • 2020-11-22 12:14

    in php.ini file,uncomment this one

    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
    ;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
    

    and in sendmail.ini

    smtp_server=smtp.gmail.com
    smtp_port=465
    error_logfile=error.log
    debug_logfile=debug.log
    auth_username=your@gmail.com
    auth_password=yourpassword
    force_sender=your@gmail.com
    hostname=localhost
    

    configure this one..it will works...it working fine for me.

    thanks.

    0 讨论(0)
提交回复
热议问题