I've been trying to send an email from a php file. I configured some xampp files but still not working and I can't figure where is the problem. I followed more than an tutorial online but still didn't work.
here is my php.ini
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
;SMTP = smtp.gmail.com
smtp_port = 587
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
mail.add_x_header=Off
here's sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
; if your smtp server requires authentication, modify the following two lines
auth_username=user@gmail.com
auth_password=xxxxxxx
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.
pop3_server=
pop3_username=
pop3_password=
; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
force_sender=user@gmail.com
here's my php send code
<?php
$to = "user2@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: user@gmail.com" . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo ("Message successfully sent!");
} else {
echo ("Message delivery failed...");
}
?>