RickyHalim
RickyHalim

Reputation: 295

Localhost Sendmail does not work

I am a beginner in PHP, and I am trying to send mail from my localhost but it does not work. Been looking through some solutions but nothing seems to help. Someone please advise.

Here is my sendmail.ini file (saved in C:\xampp\sendmail\sendmail.exe)

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=my-password
[email protected]

Here is a fraction of my php.ini on the SMTP part:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-id.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Here is my PHP file:

<?php 
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

if (mail($to, $subject, $body)) {
    echo("<p>Message successfully sent!</p>");
} else {
    echo("<p>Message delivery failed...</p>");
}
?>

I always receive "Message delivery failed no matter what I try. Please help

Upvotes: 0

Views: 356

Answers (1)

Robyt3
Robyt3

Reputation: 63

Make sure to comment out the mail-functions you are not using in your php.ini:

[mail function]
;SMTP = localhost
;smtp_port = 25
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

SMTP and smtp_port are only needed if you are running your own smtp server. The second sendmail_path runs a program that writes all mails to the mailoutput folder.

Upvotes: 0

Related Questions