Asked  7 Months ago    Answers:  5   Viewed   29 times

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

$to      = '';
$subject = 'Fake sendmail test';
$message = 'If we can read this, it means that our fake Sendmail setup works!';
$headers = 'From:' . "rn" .
           'Reply-To:' . "rn" .
           '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_port =587
sendmail_from =
sendmail_path = ""C:xamppsendmailsendmail.exe" -t"

Configuration for sendmail.ini

error message in sendmail error log with port 587

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



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:

[Modify] the php.ini file to use it (commented out the other lines):

[mail function]
; For Win32 only.
; SMTP =
; smtp_port = 25

; For Win32 only.
; sendmail_from = <e-mail username>

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:xamppsendmailsendmail.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:

force_sender=<e-mail username>

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

Wednesday, March 31, 2021
answered 7 Months ago

Finally I found the answer.

The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.

  1. Right click on sendmail.exe
  2. Properties
  3. Compatibility
  4. Change the configuration for all users
  5. Execute as Windows XP SP 3
  6. Execute as adminitrator

And save :D

2 days lost in this nonsense :(

Wednesday, March 31, 2021
answered 7 Months ago

Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. At last I have found this way to send mails (using WAMP, XAMPP, etc.):

Install hMailServer

Configure this hMailServer setting:

  1. Open hMailServer Administrator.
  2. Click the "Add domain ..." button to create a new domain.
  3. Under the domain text field, enter your computer's localhost IP.
    • Example: is your localhost IP.
  4. Click the "Save" button.
  5. Now go to Settings > Protocols > SMTP and select the "Delivery of Email" tab.
  6. Find the localhost field enter "localhost".
  7. Click the Save button.

Configure your Gmail account, perform following modification:

  1. Go to Settings > Protocols > SMTP and select "Delivery of Email" tab.
  2. Enter "" in the Remote Host name field.
  3. Enter "465" as the port number.
  4. Check "Server requires authentication".
  5. Enter your Google Mail address in the Username field.
  6. Enter your Google Mail password in the password field.
  7. Check mark "Use SSL"
  8. Save all changes.


If you want to send email from another computer you need to allow deliveries from External to External accounts by following steps:

  1. Go to Settings > Advanced > IP Ranges and double click on "My Computer" which should have IP address of
  2. Check the Allow Deliveries from External to External accounts Checkbox.
  3. Save settings using Save button.
Wednesday, March 31, 2021
answered 7 Months ago

Try using SMTP server with gmail.


or else there are many PHP mailer library. which simplifies things for you and makes it so easier to use. my fav is swift mailer. the best part about is you don't have to mess with your core php configuration file and the documentation too is very easy to read.

for example if you want to send a mail using PHP's swift mailer library it is as simple as.

require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('', 25)
  ->setUsername('your username')
  ->setPassword('your password');

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('' => 'John Doe'))
  ->setTo(array('', '' => 'A name'))
  ->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

you can refer the documentation for more information on the official website

Wednesday, March 31, 2021
answered 7 Months ago

Resolved! I hope this helps others in the future.. Even though I enabled gmail "access to less secure apps" it kept rejecting the PHPmailer sign in.. Seems that for some reason gmail wasn't accepting port 587, at least for me, so I switched it to 465 and everything started working right a way.

As a plus for this answer, as for what @Amit Merchant suggested in the comment section, I wasn't aware of what the last comment in says, it basically shows a gmail feature I never found or heard when looking for a solution for my problem, that this:

I'm sure this will help someone some day whether if it's for phpmailer or any other library.

Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :