Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 been reading and trying many so called 'simple way' to send email but the result are disappointing, none of them work for me. Below are the code, the configurations and the error message. Can someone enlighten me with this? Thanks.

php code

<?php $to      = '[email protected]'; $subject = 'Fake sendmail test'; $message = 'If we can read this, it means that our fake Sendmail setup works!'; $headers = 'From: [email protected]' . "\r\n" .            'Reply-To: [email protected]' . "\r\n" .            'X-Mailer: PHP/' . phpversion();  if(mail($to, $subject, $message, $headers)) {     echo 'Email sent successfully!'; } else {     die('Failure: Email was not sent!'); } ?> 

Configuration for php.ini (I'm using gmail mail server)

SMTP =smtp.gmail.com
smtp_port =587
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Configuration for sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=mypassword
[email protected]

error message in sendmail error log with port 587

13/10/02 13:36:41 : Must issue a STARTTLS command first. k4sm129639pbd.11 - gsmtp

like image 947
ani Avatar asked Oct 02 '13 07:10

ani


People also ask

Can I send email from localhost XAMPP?

You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost. For example, you can configure C:\xampp\php\php. ini and c:\xampp\sendmail\sendmail.

Can I send email from localhost PHP?

Send Email from Localhost with PHPSet SMTP credentials (host, username, password, and port). Specify sender name and email ( $mail->setFrom ). Set recipient email address ( $mail->addAddress ). Set email subject ( $mail->Subject ).

Is Gmail an SMTP server?

Use the Gmail SMTP server If you connect using SSL or TLS, you can send mail to anyone inside or outside of your organization using smtp.gmail.com as your server. This option requires you to authenticate with your Gmail or Google Workspace account and passwords.


Video Answer


1 Answers

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)

like image 70
ani Avatar answered Sep 23 '22 15:09

ani